Ubuntu 安装 MySQL #27
onnttf
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
下载安装
获取
mysql-apt-config
文件下载地址MySQL
官网,选择 APT Repository。 >>>直达链接上面得到的链接地址即为
mysql-apt-config
的下载地址。本文发表之时的最新地址为:
https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
安装
mysql-apt-config
在阅读下面的内容前,请先登录您的服务器。
这时会有一个可视化界面出现,如下图所示。
选择第一项,可以看到让我们选择
MySQL
的版本,我这边选择的是 5.7 版本。然后一路Ok
下去就可以了。安装其他 mysql 相关服务
如果出现一个要求输入数据库密码的界面的话,那么按着提示进行操作(输入密码,再次输入密码,确认)。如果没有看到这个界面,也不必惊慌(反正我也没有看到这个界面…🙄️),下一小节会讲解如何设置密码。
MySQL
安装完成后会自动启动,可以通过sudo service mysql status
检查运行状态,控制台中输下面的内容就表示MySQL
正在运行。其他常用命令:
修改密码
MySQL 5.7
安装完成后普通用户不能进 mysql,原因:root
的plugin
被修改成了auth_socket
,用密码登陆的plugin
应该是mysql_native_password
,直接用root
权限登录就不用密码,修改root
密码和登录验证方式。通过上面的代码,就将
MySQL
的密码设置成了 123456,我们可以检查下密码是否设置成功:新增用户
执行新增用户的
SQL
语句注: 'zhangpeng'@'%'表示 zhangpeng 这个账号允许远程登录。如果写成 'zhangpeng'@'localhost' ,那么只能本地登录。
设置字符集
MySQL
的默认字符集不是 utf8,因此我们需要修改MySQL
的字符集。编辑配置文件(
/etc/mysql/mysql.conf.d/mysqld.cnf
),将下面内容填入配置文件。修改完毕后,检查字符集是否设置成功
远程登录
参考资料
Beta Was this translation helpful? Give feedback.
All reactions