ubuntu18.04下载使用mysql5.7.37
原创ubuntu18.04安装mysql5.7.37
1.1 安装
执行下面三条命令:
# 安装mysql服务
sudo apt-get install mysql-server
# 安装客户端
sudo apt install mysql-client
# 安装依赖
sudo apt install libmysqlclient-dev
# 检查状态
sudo netstat -tap | grep mysql
呈现下面截图状况则表明安装成功:

1.2 设置mysql的root密码
mysql5.7安装完成后普通用户不能进mysql,原因:root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password,直接用root权限登录就不用密码,修改root密码和登录验证方式。
操作如下:
$ sudo su #进入root目录下
# mysql #进入mysql
mysql>
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(123456), plugin=mysql_native_password where user=root;#将root重置为123456
mysql> flush privileges; #使上面操作生效
mysql> exit
Bye
# exit
$ sudo /etc/init.d/mysql restart #重启mysql服务
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.22-0ubuntu18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type help; or h for help. Type c to clear the current input statement.
mysql>
其中, flush privileges; 命令:
flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。
具体可参考:
https://www.cnblogs.com/enjie/articles/7898587.html
操作过程截图如下:


1.3 配置mysql远程登陆
# 修改配置文件,注释掉bind-address = 127.0.0.1
$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
# 保存退出,然后进入mysql服务,执行授权命令:

$ mysql -uroot -p
mysql> grant all on *.* to root@% identified by 123456 with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec) #赋权操作,具体解释见下面
mysql> flush privileges; #使前面操作生效
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ sudo /etc/init.d/mysql restart #再次启动mysql服务
其中:
grant all on *.* to root@% identified by 123456 with grant option;
grant:赋权命令
all:当前用户的所有权限
on:介词
. :当前用户对所有数据库和表的相应操作权限
to:介词
‘root’@’%’:权限赋给root用户,所有ip都能连接
连接时输入密码,密码为123456
with grant option:允许级联赋权
具体可参考:
https://blog.csdn.net/u010953706/article/details/95985946
1.4 查看mysql版本及安装位置
查看版本
mysql -V #查看版本
whereis mysql #查看mysql安装位置
which mysql #运行文件所在路径

总结
参考资料:
1、整体流程可参考:
https://blog.csdn.net/wrongyao/article/details/81840544
2、查看mysql安装路径可参考:
https://blog.csdn.net/weixin_29587015/article/details/116692671
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123




