给 MySql 添加外链指令
1.执行以下命令分配新用户:
# 合并成一条语句:模板
grant [all|select|insert|update|delete] on <database>.<table> to <user>@<localhost> identified by 'pass';
# 合并成一条语句:demo
grant select,insert,update,delete on *.* to 'test'@'127.0.0.1' identified by '123456';
grant all privileges on *.* to '用户名'@'IP地址' identified by '密码';
# 分开2条语句先创建用户 再给用户赋所有权限
CREATE USER '用户名'@'IP地址' IDENTIFIED BY '密码';
GRANT ALL ON *.* TO '用户名'@'IP地址';
# 创建账号并赋值指定权限
CREATE USER 'test'@'localhost' IDENTIFIED BY 'pass';
GRANT select ON *.* TO 'test'@'localhost';
# mysql8 语法
alter user 'root'@'%' identified with mysql_native_password by '123456';
# 删除用户
drop user root@'%';
2.执行完上述命令后用下面的命令刷新权限
flush privileges;
# 查看mysql默认密码
cat /var/log/mysqld.log
cat /var/log/mysqld.log | grep root@localhost:
3.重启mysql服务
Ubuntu
启动mysql:
方式一:sudo /etc/init.d/mysql start
方式二:sudo service mysql start
停止mysql:
方式一:sudo /etc/init.d/mysql stop
方式二:sudo service mysql stop
重启mysql:
方式一:sudo/etc/init.d/mysql restart
方式二:sudo service mysql restart