ubuntu-mysql 配置

89 阅读1分钟

1.配置IP

进入/etc/mysql/mysql.conf.d/目录,编辑mysqld.cnf,在里面找到
bind-address = 127.0.0.1
将其改为 bind-address = 0.0.0.0,即可实现允许任意IP的访问。

2.授权grant

  • 用root账户登录MySQL数据库;

  • 授权用户能进行远程连接: grant all on *.* to username@'%' identified by 'password';

    注意:username是用户名,password是要自己填写的一个名字, 例如:grant all on . to root@’%’ identified by ‘root’; “.”:第一个代表数据库名;第二个代表表名。这里的意思是所有数据库里的所有表都授权给用户。 root:授予root账号。 “%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。 “password”:分配账号对应的密码,这里密码自己替换成你的mysql root帐号密码。

3.刷新+启动

  • 刷新操作:执行flush privileges;
  • 重启mysql: sudo /etc/init.d/mysql restart

常用命令

数据库 远程 用户初始化语句:
update mysql.user set authentication_string=password('xxx') where user='root'
grant all on . to root@'%' identified by 'xxx';

连接语句
mysql -uroot -p -h89.xx.xx.xx -P3306

启动
/etc/init.d/mysql start
关闭
/etc/init.d/mysql stop