初次安装mysql,net start mysql,然后输入mysql -u root -p,出现enter password,我直接点击回车,结果出现如果下错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)。网上看了很多方法,都是千篇一律的,没有解决我的问题
使用:set password for 'root'@'localhost' =password('');
flush privileges;
还是不行,当输入set password for 'root'@'localhost' =password('');时就出现no database seleced错误
#1.停止mysql数据库
/etc/init.d/mysqld stop
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
#4.更新root密码
mysql> update user set authentication_string=password('root') where user='root';
#5.刷新权限
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init.d/mysqld restart
#8.使用root用户重新登录mysql
mysql -u root -p
Enter password: <输入新设的密码root>
MySql5.6操作时报错:You must SET PASSWORD before executing this statement解决
mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.03 sec)MySQL> create database roger;Query OK, 1 row affected (0.00 sec)也就是用mysql> SET PASSWORD = PASSWORD('123456');这句话重新设置一次密码!