centos7安装MySQL Community Server 8.0.19

1.下载glib安装包 mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
centos7安装MySQL Community Server 8.0.19_第1张图片
centos7安装MySQL Community Server 8.0.19_第2张图片
centos7安装MySQL Community Server 8.0.19_第3张图片

centos7安装MySQL Community Server 8.0.19_第4张图片
centos7安装MySQL Community Server 8.0.19_第5张图片

2.用远程登录工具上传到 /opt 目录下 目录随意啦
远程登录工具 多种多样,我用的是xftp 和xshell,也可以用 vmtools从windows 拷贝到虚拟机

3.解压 ,xz的解压方式自行百度,在这里安利一下

xz压缩文件解压方法参考链接

tar -Jxvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz

4.移动解压得到的文件到 /usr/local/目录下,重新命名为mysql

mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql

5.创建mysql 和mysql用户组,不可以登录

useradd -r -s /sbin/nologin mysql 

6.修改 /usr/local/mysql/ 目录的权限

chown -R mysql.mysql /usr/local/mysql/

7.删除预装系统时带的配置文件 ,不删除后面启动会报错

rm -rf /etc/my.cnf

8、进入bin目录初始化,必须在bin目录完成

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql

9.该命令会生成root的默认密码,必须记住

[root@localhost bin]# ./mysqld --initialize --user=mysql
2020-02-22T04:57:59.633587Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 73864
2020-02-22T04:58:02.680256Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 1YD6w6Vw+<a&

如上,我的初始默认密码是 1YD6w6Vw+

10.弄服务

cp ../support-files/mysql.server  /etc/init.d/mysqld

11.启动MySQL服务

service mysqld start

启动成功如下:

[root@localhost bin]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
. SUCCESS! 

12.启动MySQL命令行测试

必须在bin目录执行
cd /usr/local/mysql/bin
./mysql -u root -p

此时需要输入刚才初始化时的初始默认密码
[root@localhost bin]# ./mysql -u root -p
Enter password: xxxxxxxxxxxxx(这里是密码,输入的时候看不见,输入完密码后回车)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

Copyright (c) 2000, 2020, 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>

13.修改root的密码 为111

mysql> alter user 'root'@'localhost' identified by '111';
Query OK, 0 rows affected (0.01 sec)


退出重新登录
mysql> exit
Bye

再次启动MySQL命令行测试
[root@localhost bin]# ./mysql -u root -p


Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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>

终端显示

mysql>

即代表大功告成

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