在mysql/bin目录下有个是mysqladmin工具用来管理和操作mysql用的,我们用他来给 root 加上密码
[root@localhost mysql]#bin/mysqladmin -uroot password 123456
这样我们就给root设置了 123456 这个密码
再次登录
[root@localhost mysql]# bin/mysql
上次我们使用这个命令连接mysql,看看密码是否生效。
[root@localhost mysql]# bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost mysql]#
进不去了,说明密码设置成功。
我们在用密码试试,这时应该说明是什么用户登录,这里我们用的是 root 这个用户。
[root@localhost mysql]# bin/mysql -uroot -p
Enter password:   这里密码是不显示的,不要按错键盘就行
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 5.0.2-alpha
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>