Ubuntu16.04如何安装MySQL5.7?
安装主程序
主程序安装就我知道有两种方式:
- 使用apt-get全自动安装
# 安装命令 apt-get install mysql-server # 安装过程中需要输入mysql的root密码
使用dpkg手动安装依赖包
# 1. 下载安装包 # 我测试过程中下载的是:mysql-server_5.7.16-1ubuntu16.04_amd64.deb-bundle.tar # 国内镜像站:http://mirrors.sohu.com/mysql/MySQL-5.7/ wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-server_5.7.16-1ubuntu16.04_amd64.deb-bundle.tar # 2. 解压安装包 # 解压后将出现: # libmysqlclient20_5.7.16-1ubuntu16.04_amd64.deb # mysql-common_5.7.16-1ubuntu16.04_amd64.deb # mysql-community-source_5.7.16-1ubuntu16.04_amd64.deb # mysql-testsuite_5.7.16-1ubuntu16.04_amd64.deb # libmysqlclient-dev_5.7.16-1ubuntu16.04_amd64.deb # mysql-community_5.7.16-1ubuntu16.04_amd64.changes # mysql-community-test_5.7.16-1ubuntu16.04_amd64.deb # libmysqld-dev_5.7.16-1ubuntu16.04_amd64.deb # mysql-community-client_5.7.16-1ubuntu16.04_amd64.deb # mysql-server_5.7.16-1ubuntu16.04_amd64.deb # mysql-client_5.7.16-1ubuntu16.04_amd64.deb # mysql-community-server_5.7.16-1ubuntu16.04_amd64.deb tar -xvf ../mysql-server_5.7.16-1ubuntu16.04_amd64.deb-bundle.tar -C ./ # 3. 使用dpkg安装依赖包 dpkg -i mysql-common_5.7.16-1ubuntu16.04_amd64.deb dpkg -i libmysqlclient20_5.7.17-1ubuntu16.04_amd64.deb dpkg -i libmysqlclient-dev_5.7.17-1ubuntu16.04_amd64.deb dpkg -i libmysqld-dev_5.7.17-1ubuntu16.04_amd64.deb # 上面四个包安装应该都没有什么问题,接下来安装的包将会抛出缺少依赖包的错误 # 所缺包名当时搞忘了记下来,请仔细看一下错误信息,然后使用apt-get安装一下即可 dpkg -i mysql-community-client_5.7.17-1ubuntu16.04_amd64.deb dpkg -i mysql-client_5.7.17-1ubuntu16.04_amd64.deb dpkg -i mysql-community-source_5.7.17-1ubuntu16.04_amd64.deb # 接下来我们需要安装mysql-community-server包了,安装之前还需要按照一个依赖包:libmecab2 apt-get install libmecab2 dpkg -i mysql-community-server_5.7.17-1ubuntu16.04_amd64.deb ## 安装过程中需要输入mysql的root密码
至此,我们已经完成了主程序安装,并可以在本机使用MySQL -u root -p进行登录数据库了。
开放远程访问
开启root用户的全称访问权限
1、修改数据库中user的host
sh # 使用mysql -u root -p登录到数据库,然后依次执行下面语句 # xxxxxx表示root用户的密码 use mysql; update user set host = '%' where user ='root'; grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx'; flush privileges;
2、修改my.conf的中的ip绑定
sh # 进入编辑/etc/mysql/mysql.conf.d/mysqld.conf vi /etc/mysql/mysql.conf.d/mysqld.conf # 修改ip绑定 # 源文件中为: bind-address 127.0.0.1 # 将其修改为: bind-address 0.0.0.0 # 覆盖保存 esc:wq
3、重启数据库
sh # 重启命令 service mysql restart
新增用户并允许远程访问
# 新增用户并允许远程访问只需要在user表中增加一个用户,将host设置为%即可 # 下例默认将所有权限分配给新用户,例如: grant all privileges on *.* to 'lethew'@'%' identified by 'abcdef'; flush privileges;
参考资料
主程序安装://www.gxlcms.com/article/103353.htm
开放远程访问://www.gxlcms.com/article/103764.htm
解决10061问题:https://www.digitalocean.com/community/questions/can-t-connect-to-mysql-server-on-ipaddress-10061