CentOS安装MySQL问题汇总
遇到的错误
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for user 'root'@'localhost' (using password: NO)
描述:刚安装完MySQL,第一次登陆。
[wangyang@CentOS ~]$ mysql -u root -p Enter password: #我记得root初始是没密码的,这句直接回车 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for user 'root'@'localhost' (using password: NO)
然后我就直接尝试修改MySQL的root密码:
[wangyang@CentOS ~]$ mysqladmin -u root -p password 123456 Enter password: mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'
问题是什么我没弄清楚,解决方案如下:
[root@CentOS ~]# service mysql stop [root@CentOS ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [wangyang@CentOS ~]$ mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; #newpassword为root新密码 mysql> FLUSH PRIVILEGES; mysql> quit [root@CentOS ~]# service mysql start [wangyang@CentOS ~]$ mysql -u root -p Enter password: #输入新密码,OK
You must SET PASSWORD before executing this statement
描述:参考前文利用安全模式成功登陆,然后修改密码,等于给MySql设置了密码。登陆进去后,想创建一个数据库测试下。得到的结果却是:
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
解决方法:
mysql> create database localtest; ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected (0.03 sec) mysql> create database yan1; Query OK, 1 row affected (0.00 sec)
不懂为什么再设置一遍密码。