MySQL常见问题

MySQL初始化密码

# 停止mysql服务
service mysql stop
cd %mysql_home%/bin
# 取消密码登录
mysqld_safe --skip-grant-tables --skip-networking &
# 进行mysql交互式窗口
mysql -u root
#使用SQL语句修改密码
update mysql.user set password=password('yourpass') where user='root' and Host = 'localhost';
#停止mysqld_safe
ps aux | grep -v grep | grep mysqld_safe | awk '{print $2}' | xargs kill -9
# 启动mysql服务
service mysql start

MySQL远程登录失败

网络原因

首先判断网络是否通畅,若不通畅可能是防火墙等原因

telnet ip port | grep connect
nc -v ip port && echo ok

权限设置原因

参考:https://blog.csdn.net/lsmrsun/article/details/53140448
直接将root的 “localhost” 修改为 “%”, 允许所有IP使用root登录,这样是不安全的

use mysql
update user set host = '%' where user ='root';    

给予指定IP远程root(或者自建账号)全部权限,也不是很安全。

#此处的 *.* 代码所有数据库的所有表
grant all on *.* to root@"10.1.1.1" Identified by "password"; 
flush privileges

给予远程root(或者自建账号)部分权限,较安全。

#此处的 *.* 代码所有数据库的所有表
grant select,insert,update,delete on *.* to root@"%" Identified by "password"; 
#刷新权限,无需重启
flush privileges

MySQL常见错误

Question

You must reset your password using ALTER USER statement before executing this statement.

Answer

新设置密码即可,参考:https://www.cnblogs.com/debmzhang/p/5013540.html

SET PASSWORD = PASSWORD('your new password');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值