ubuntu18.04安装mysql5.7

一、安装MySQL

在Ubuntu中,默认情况下,只有最新版本的MySQL包含在APT软件包存储库中,要安装它,只需更新服务器上的包索引并安装默认包apt-get。

sudo apt-get update

1、安装mysql服务:

sudo apt install mysql-server-5.7

在这里插入图片描述

2、检查状态:

需要先安装net-tools

sudo apt install net-tools
sudo netstat -tap | grep mysql

3、注意查看mysql版本使用:

mysql -V

在这里插入图片描述

4、查看MySQL5.7默认账号和密码:

sudo cat /etc/mysql/debian.cnf

在这里插入图片描述

二、配置MySQL

sudo mysql_secure_installation
配置项较多,如下所示:

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
 Please set the password for root here...
 New password: (输入密码)
Re-enter new password: (重复输入)

#3
 By default, a MySQL installation has an anonymous user,
 allowing anyone to log into MySQL without having to have
 a user account created for them...
 Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
 Normally, root should only be allowed to connect from
 'localhost'. This ensures that someone cannot guess at
 the root password from the network...
 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (我的选项)

#5
 By default, MySQL comes with a database named 'test' that
 anyone can access...
 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
 Reloading the privilege tables will ensure that all changes
 made so far will take effect immediately.
 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)

三、查mysql服务状态

systemctl status mysql.service

显示如下结果说明mysql服务是正常的:
在这里插入图片描述

四、修改root账户秘密认证方式:

连接到Mysql:

sudo mysql -uroot -p

1、查看用户:

mysql> select user, plugin from mysql.user;

在这里插入图片描述

2、重置Root密码,修改认证方式:

mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql>flush privileges;
mysql> exit

五、配置远程访问mysql:

1、修改配置文件,注释掉bind-address = 127.0.0.1

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

2、保存退出,然后进入mysql服务

mysql -uroot -p

3、执行授权命令:

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

其中root@%,localhost就是本地访问,配置成%就是所有主机都可连接;第二个’123456’为你给新增权限用户设置的密码。

4、重启

sudo /etc/init.d/mysql restart

六、删除MySQL

想安装MySQL 8.0或者重装MySQL 5.7的前提条件,可以先删除已有的。

1.删除 mysql:

sudo apt autoremove --purge mysql-server-*
sudo apt remove mysql-server
sudo apt autoremove mysql-server
sudo apt remove mysql-common

2.清理残留数据

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小眼哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值