xshell 刚安装好mysql,登录mysql 报错: Access denied for user 'root'@'localhost' (using password
解决办法:
关闭mysql:
# service mysqld stop // rcmysqld stop 或者 kill -term mysql
# mysqld_safe --skip-grant-tables //就是在启动mysql时不启动grant-tables,授权表,跳过密码输入这一项直接连接mysql
启动mysql:
# service mysqld start
//连接上mysql后可以对mysql密码进行修改
mysql -u root
mysql> use mysql
mysql> UPDATE user SET Password=PASSWORD('xxx') WHERE user='root';
mysql> flush privileges; //执行
mysql>\q
很多情况下我们需要远程连接mysql数据库,那么就可以参考下面的权限设置
登录mysql:
1、xampp中的命令工具在/opt/lampp/bin/目录中,所以可以这样运行mysql命令
/opt/lampp/bin/mysql -uroot -p
2、也可以进入/opt/lampp/bin/目录执行mysql命令
cd /opt/lampp/bin/
./mysql -uroot -p
1,设置访问单个数据库权限
mysql>grant all privileges on test.* to 'root'@'%';
说明:设置用户名为root,密码为空,可访问数据库test
2,设置访问全部数据库权限
mysql>grant all privileges on *.* to 'root'@'%';
说明:设置用户名为root,密码为空,可访问所有数据库*
3,设置指定用户名访问权限
mysql>grant all privileges on *.* to 'tt'@'%';
说明:设置指定用户名为tt,密码为空,可访问所有数据库*
4,设置密码访问权限
mysql>grant all privileges on *.* to 'tt'@'%' IDENTIFIED BY '123';
说明:设置指定用户名为tt,密码为123,可访问所有数据库*
5,设置指定可访问主机权限
mysql>grant all privileges on *.* to 'tt'@'10.2.1.11';
说明:设置指定用户名为tt,可访问所有数据库*,只有10.2.1.11这台机器有权限访问
(下列方法保存,未尝试,转载来源:http://blog.csdn.net/ldl22847/article/details/7941962)