Fork me on GitHub

MySQL学习2_ubuntu18安装MySQL

安装

官网下载

  • 进入MySQL数据库的官网。里面有各种版本,MySQL5.5,MySQL5.6,MySQL5.7,MySQL8.0
  • 其中前三者是应用最广泛的,8.0目前刚出来,属于起步阶段,问题还是很多;而且网上的资源比较少。

MySQL5.7社区版本

笔者安装5.7,找到对应的版本。

选择安装版本

本次安装通过源码进行安装,并且选择Linux系统版本为ubuntu18.04,笔者最喜欢的版本。

下载 DEB Package

点击下载DEB安装包

安装过程

进入到安装包所在的文件目录下,笔者是Downloads下:

1
2
3
sudo dpkg -i mysql-community-source_5.7.26-1ubuntu18.04_amd64.deb 
# 更新软件源
sudo apt-get upgrade

安装客户端和环境

1
2
3
4
5
6
7
8
# 安装mysql服务
sudo apt-get install mysql-server
# 安装客户端
sudo apt install mysql-client
# 安装依赖
sudo apt install libmysqlclient-dev
# 检查状态
sudo netstat -tap | grep mysql

设置root密码

mysql5.7安装完成后普通用户不能进mysql,原因:rootplugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password,直接用root权限登录就不用密码,修改root密码和登录验证方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$sudo su  # 进入root账户
# mysql # 输入mysql,进入mysql服务 ;root账户下分隔符是#,普通用户是$

mysql> select user, plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=PASSWORD('renrenren'), plugin='mysql_native_password' where user='root'; # 修改root账户密码
mysql> flush privileges; # 刷新权限
mysql> exit # 退出msyql服务
Bye
# exit # 退出root账户,进入普通账户(第一个星号不是注释)
$ sudo /etc/init.d/mysql restart # 重启msyql服务
$ mysql -uroot -p # 进入mysql服务中,接下来输入上面步骤中设置的密码
Enter password: (上面的密码)

配置远程登录

默认的MySQL服务是只允许本地服务的,但是大部分时候需要远程服务,下面进行配置:

1
$sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf  # 进入配置文件,注释掉bind-address = 127.0.0.1

保存退出,进入mysql服务,执行授权命令:

1
2
3
4
5
6
7
8
9
$sudo -uroot -p
Enter password: (上面的密码)
mysql> grant all on *.* to root@'%' identified by 'renrenren' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>flush privileges;
mysql> exit
Bye

$sudo /etc/init.d/mysql restart # 重启mysql配置服务

卸载

卸载mysql

1
2
3
4
5
sudo apt-get autoremove --purge mysql-server
sudo apt-get autoremove --purge mysql-server-*
sudo apt-get autoremove --purge mysql-client
sudo apt-get autoremove --purge mysql-client-*
sudo apt-get remove mysql-common

删除数据

1
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

弹出的窗口都要选择yes!

删除目录

1
2
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql

清除残留

1
2
sudo apt autoremove
sudo apt autoreclean

MySQL解决普通用户登录等问题
Linux系统ubuntu18.04安装MySQL5.7

本文标题:MySQL学习2_ubuntu18安装MySQL

发布时间:2019年10月01日 - 13:10

原始链接:http://www.renpeter.cn/2019/10/01/MySQL%E5%AD%A6%E4%B9%A02_ubuntu18%E5%AE%89%E8%A3%85MySQL.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea