Mysql Access denied for user 'root'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决方法: 更改root密码
原密码为空,更改root密码
# service mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking然后登陆mysql
sudo mysql -u root,设置密码
mysql> use mysql; mysql> update user set password=password('新密码') where user='root'; mysql> flush privileges; mysql> quit重启数据库再次登陆即可
# service mysql restart Enter password: <输入新设的密码>
增加一个数据库用户
mysql> insert into mysql.user (Host,User,Password) VALUES('%','your username',PASSWORD('your password')); mysql> flush privileges;
创建数据库
create database DatabaseName;grant select,insert,update,delete,create,drop,alter on DatabaseName.* to username@localhost identified by 'password';
把数据库权限全部授予指定用户
grant all privileges on DatabaseName.* to 'username'@'%';
远程登陆
授权用户root使用密码123456从任意主机连接到mysql服务器:
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; flush privileges;授权用户test使用密码123456,从指定ip为123.4.5.6的主机连接到mysql服务器:
grant all privileges on *.* to 'test'@'123.4.5.6' identified by '123456' with grant option; flush privileges;然后我们查询用户情况
mysql> use mysql; mysql> select Host,User from user;如果是类似与这样的输出,test前有%,代表从任意主机登陆
+----------------+------+ | Host | User | +----------------+------+ | % | test | | 123.4.5.6 | test | | localhost | root | +----------------+------+比如我想让root从任意ip远程访问,也可以在这里直接修改
mysql> update user set host = '%' where user = 'root';
备份mysql数据库
mysqldump -u 用户名 -p 密码 数据库名 > back.sql //备份指定数据库 mysqldump --all-databases > bak.sql //备份所有数据库还原mysql数据库
mysql -u 用户名 -p 密码 数据库名 < bak.sql
转载于:https://www.cnblogs.com/ssooking/p/6385783.html