(1)
mysql修改root密码
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET
Password = PASSWORD('newpass') WHERE user = 'root';(password字段mysql可能会没有,需要使用
authentication_string)--->mysql5.7版本前
mysql> UPDATE user SET
authentication_string= PASSWORD('newpass') WHERE user = 'root'; --->mysql5.7
mysql> FLUSH PRIVILEGES;
(2)
创建用户
create user 'suncht'@'%' identified by 'm,./1234';
其他例子: CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';
(3)
授权
grant all on *.* to 'suncht'@'%';
其他例子: GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
(4)
设置与更改用户密码
可以类似于“
mysql修改root密码”
命令:SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
如果是当前登陆用户用SET PASSWORD = PASSWORD("newpassword");
例子: SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");
(5)创建数据库
create database test01;
问题:
配置文件中增加skip-grant-tables,
如: skip-grant-tables=1
重启mysql后重新登录授权报错:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
这个错误执行flush privileges后再次授权就可以了。
(6)初始化过程出现的一些问题:
问题:(mysql 5.7以上的版本)
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决方案:
alter user user() identified by '123456';
问题:只能通过127.0.0.1可以访问mysql,如果用真实IP地址访问mysql,提示连接不上。
解决方案:在my.ini中将bind-address=127.0.0.1 改成 bind-address=0.0.0.0
问题:mysql限制客户端访问登录
把用户的host字段改成%, %表示任何ip客户端都可以连接
update user set host='%' where user='root';