Linux下安装配置MySQL8.0——安装MySQL、修改密码、添加软链接、设置远程连接

一、下载mysql

MySQL官网

Linux下安装配置MySQL8.0——安装MySQL、修改密码、添加软链接、设置远程连接_第1张图片

二、查看Linux自带的mysql并移除

[root@localhost opt]# rpm -qa|grep mysql
mysql-community-release-el7-5.noarch
[root@localhost opt]# rpm -e --nodeps mysql-community-release-el7-5.noarch

三、新建mysql用户和用户组,并设置用户密码

[root@localhost opt]# groupadd mysql
[root@localhost opt]# useradd -r -g mysql mysql
[root@localhost opt]# passwd mysql
Changing password for user mysql.
New password: 
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.

四、解压mysql文件

[root@localhost opt]# tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

五、将文件重命名为MySQL

[root@localhost opt]# mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql

六、更改MySQL文件的用户组、用户和权限

[root@localhost mysql]# chown -R mysql:mysql /opt/mysql
[root@localhost mysql]# chmod -R 755 /opt/mysql

七、编译安装并初始化MySQL(记住最后一行末尾的密码)

[root@localhost mysql]# cd bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/opt/mysql/data --basedir=/opt/mysql
2020-07-26T07:55:52.200143Z 0 [System] [MY-013169] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 60394
2020-07-26T07:55:52.269404Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-26T07:55:54.398873Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-26T07:55:58.654283Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: NIux

八、启动MySQL

[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# ./mysql.server start
Starting MySQL.Logging to '/opt/mysql/data/localhost.localdomain.err'.
..                                                         [  OK  ]

九、创建软链接并重启MySQL

[root@localhost support-files]# ln -s /opt/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost support-files]# ln -s /opt/mysql/bin/mysql /usr/bin/mysql
[root@localhost support-files]# service mysql restart
Shutting down MySQL...                                     [  OK  ]
Starting MySQL..                                           [  OK  ]

十、登录MySQL,修改密码。(登陆密码是编译时最后一行的密码)

[root@localhost support-files]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21

十一、修改密码

mysql>  ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
Query OK, 0 rows affected (0.04 sec)

刷新:

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

ctrl+z退出,重新登录MySQL试试密码。

十二、设置远程连接

mysql> update user set host='%' where user='root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

刷新:

mysql> flush privileges;

Query OK, 0 rows affected (0.02 sec)

现在可以通过可视化工具,试试远程连接了。

Linux下安装配置MySQL8.0——安装MySQL、修改密码、添加软链接、设置远程连接_第2张图片

你可能感兴趣的:(数据库)