MySql管理合集

来源:互联网 发布:淘宝秒杀有人抢到了吗 编辑:程序博客网 时间:2024/04/27 13:21
启动MySQL服务: sudo start mysql

停止MySQL服务: sudo stop mysql

修改 MySQL 的管理员密码: sudo mysqladmin -u root password newpassword


设置外网ip访问:

正常情况下,mysql占用的3306端口只是在IP 127.0.0.1上监听,拒绝了其他IP的访问(通过netstat可以查看到)。
取消本地监听需要修改 my.cnf 文件:
sudo vi /etc/mysql/my.cnf
bind-address = 127.0.0.1 //找到此内容并且注释

此时如果报错:1130 - Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server

你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql -u root -p

输入密码之后

mysql> use mysql;

mysql> select host, user from user;

查出来的结果是这样的


执行

mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

这时是这样的


此时,应该删除所有user为root而host不是%的行

mysql> delete from user where user='root' and host <>'%';

mysql> select host, user from user;

此时是这样的


此时就可以从外面用ip+端口号连进来了。



0 0