Skip to content

Instantly share code, notes, and snippets.

@wgm89
Last active December 19, 2015 15:19
Show Gist options
  • Select an option

  • Save wgm89/5975417 to your computer and use it in GitHub Desktop.

Select an option

Save wgm89/5975417 to your computer and use it in GitHub Desktop.
fix mysql how to fix Access denied for user 'root'@'localhost'
php 可以连接 mysql , 但 cli 下 不能使用密码登录 ,空密码可登录,应该是权限在作怪.
skip-grant-tables下 不能 分配mysql 用户权限 .
只能这样 : mysql_query(GRANT ALL ON mydb.* TO 'someuser'@'somehost';);
通常以下就可解决:
Follow steps below
1.Start the mysql server instance or daemon with the --skip-grant-tables option. (security setting)
$ mysqld --skip-grant-tables
2.Then Execute these statements.
$ mysql -u root mysql
$mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';
$mysql> FLUSH PRIVILEGES;
3.Finally, restart the instance/daemon without the --skip-grant-tables option.
$ /etc/init.d/mysql restart
4.You should be able to connect with your new password.
$ mysql -u root -p
Enter password: my_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment