3. chkconfig mysqld on 命令配置mysql随系统自启动
4.chkconfig --list mysqld 查看配置结果
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 如果2--5为on的状态就OK
5. /etc/rc.d/init.d/mysqld start ← 启动MySQL服务
6. mysql -u root ← 用root用户登录MySQL服务器,控制台显示:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
7. set password for root@localhost=password('在这里填入root密码'); ← 设置root密码
Query OK, 0 rows affected (0.01 sec)
set password for root@cloud=password('在这里填入root密码'); ← 设置root密码
Query OK, 0 rows affected (0.01 sec)
set password for root@127.0.0.1=password('在这里填入root密码'); ← 设置root密码
Query OK, 0 rows affected (0.01 sec)
8. select user,host,password from mysql.user; ← 查看用户信息
+------+-----------+------------------+
| user | host | password |
+------+-----------+------------------+
| root | localhost | 435e5b2459c49408 |
| root | cloud | 435e5b2459c49408 |
| root | 127.0.0.1 | 435e5b2459c49408 |
| | localhost | |
| | cloud | |
+------+-----------+------------------+
5 rows in set (0.00 sec
9. mysql> delete from mysql.user where user=''; ← 删除匿名用户
Query OK, 2 rows affected (0.17 sec)
10. exit ← 退出MySQL服务器
11. mysql -u root ← 通过空密码用root登录
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) ← 出现此错误信息说明密码设置成功
12. mysql -u root -p ← 通过密码用root登录
Enter password: ← 在这里输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.77 Source distribution