跟老齐学Python之网站的结构

2019-10-05 14:37:29刘景俊

这样,看官的电脑上就已经安装好了这个数据库。当然,当然,还要进行配置。

第二步,配置MySQL

默认的MySQL安装之后根用户是没有密码的,看官注意,这里有一个名词“根用户”,其用户名是:root。运行:

$mysql -u root

在这里之所以用-u root是因为我现在是一般用户(firehare),如果不加-u root的话,mysql会以为是firehare在登录。注意,我在这里没有进入根用户模式,因为没必要。一般来说,对mysql中的数据库进行操作,根本没必要进入根用户模式,只有在设置时才有这种可能。

进入mysql之后,会看到>符号开头,这就是mysql的命令操作界面了。

下面设置Mysql中的root用户密码了,否则,Mysql服务无安全可言了。

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";

注意,我这儿用的是123456做为root用户的密码,但是该密码是不安全的,请大家最好使用大小写字母与数字混合的密码,且不少于8位。

以后如果在登录数据库,就可以用刚才设置的密码了。

除了上面的安装过程,看官如果用的是别的操作系统,可以在google上搜索相应的安装方法,恕我不在这里演示,因为我只能演示在ubuntu上的安装流程。不过,google会帮你解决安装遇到的问题。

运行mysql

安装之后,就要运行它,并操作这个数据库,建立一个做网站的基础。我这样来运行数据库:

qw@qw-Latitude-E4300:~$ mysql -u root -p
Enter password:

输入数据库的密码,之后出现:

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 373
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>

看到这个界面内容,就说明你已经进入到数据里面了。接下来就可以对这个数据进行操作。例如:

mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| carstore      |
| cutvideo      |
| itdiffer      |
| mysql       |
| performance_schema |
| phpcms       |
| phpcms2      |
| pushsystem     |
| sipras       |
| test        |
+--------------------+