Ubuntu server安装MySQL并配置远程连接

1.  在Ubuntu server 安装MySQL(过程中注意记住设置的密码)

Sudo apt-get install mysql

Sudo apt-get install mysql-server

Sudo apt-get install mysql-client

备注:此处遇到MySQL无法安装的问题,提示dpkg:error processing package open-vm-tools(--configure)错误,解决方法是清除open-vm-tools之后重新安装,sudo apt-get purge open-vm-tools, sudo apt-get install open-vm-tools.

2. 配置MySQL连接账户

         进入MySQL环境(mysql –u root –p)

         User mysql

         添加账户

(insert into mysql.user(Host,User,Password) values (“localhost”,”test”,password(“pass”));)

localhost指的本地,如果需要远程连接,host可设置为”%”

备注:在使用用户进入MySQL环境时,遇到提示access denied问题,解决方法是更新mysql.user表中的authentication_string字段,update mysql.user set authentication_string=password(‘pass’) where user=’test’ and Host=’localhost’

3. 对用户进行授权

         命令:grant all privileges on databasename.tablename to ‘test’ @’localhost’ identified by ‘pass’ with grant option;

         databasename - 数据库名,tablename-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示,如*.*

         @后指代主机,需要全部则添加@’%’

4. 远程使用sqlyog连接,端口默认3306

 

备注:此处遇到连接提示1045的错误,解决方式是要对mysql.user表中对应的用户,host设置为连接用ip,并设置authentication_string 和 对此用户进行授权

原文地址:https://www.cnblogs.com/alansheng/p/7600755.html