本文共 1987 字,大约阅读时间需要 6 分钟。
最新版通过命令安装mysql 8.0并配置远程连接
建议通过主机终端进行安装
通过命令安装mysql 建议使用清华源速度较快
$ sudo apt-get install mysql-server$ sudo apt-get isntall mysql-client$ sudo apt-get install libmysqlclient-dev
安装完毕后进行初始化配置, 设置密码
sudo mysql_secure_installation
配置项选择设置
#1VALIDATE PASSWORD PLUGIN can be used to test passwords...Press y|Y for Yes, any other key for No: N (我的选项)#2Please set the password for root here...New password: (输入密码)Re-enter new password: (重复输入)#3By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them...Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)#4Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network...Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)#5By default, MySQL comes with a database named 'test' thatanyone can access...Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)#6Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
到此为止MySql安装完毕, 下面开始进行远程主机连接配置.
首先用根用户进入
sudo mysql -uroot -p
这一步应该会让你输入密码 刚才设置的密码, 不行就用Ubuntu切换到root用户的密码即可.
下面这一步很重要, 因为我们安装的是MySQL8.0版本所以千万不要直接配置否则将会报1064的错误
如图所示的错误grant all privileges on . to 报错1064问题
提示意思是不能用grant创建用户,mysql8.0以前的版本可以使用grant在授权的时候隐式的创建用户,mysql8.0以后已经不支持,所以必须先创建用户,然后再授权,命令如下:mysql> CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';Query OK, 0 rows affected (0.48 sec)mysql> grant all privileges on *.* to 'root'@'%';Query OK, 0 rows affected (0.48 sec)
这两条语句, 第一条先创建root用户并设置密码
第二条设置root用户’%'代表可以操作所有数据库最后还没有结束, 必须修改配置文件中的bind-address
ctrl +z 退出 mysql命令界面 sudo su 切换到Ubuntu的root用户 使用命令sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address的值修改为0.0.0.0
然后保存保存之后使用命令
/etc/init.d/mysql restart
重启mysql服务
至此即可使用远程主机连接mysql, 完成。
转载地址:http://nilzi.baihongyu.com/