-
检查是否安装过mysql
rpm -qa|grep mariadb mariadb-libs-5.5.68-1.el7.x86_64
-
如果存在通过如下命令卸载
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
-
下载mysql包
https://dev.mysql.com/downloads/mysql/
-
上传到服务器解压
[root@hadoop207 software]# mkdir mysql [root@hadoop207 software]# tar -xvf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar -C ./mysql mysql-community-client-5.7.37-1.el7.x86_64.rpm mysql-community-common-5.7.37-1.el7.x86_64.rpm mysql-community-devel-5.7.37-1.el7.x86_64.rpm mysql-community-embedded-5.7.37-1.el7.x86_64.rpm mysql-community-embedded-compat-5.7.37-1.el7.x86_64.rpm mysql-community-embedded-devel-5.7.37-1.el7.x86_64.rpm mysql-community-libs-5.7.37-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm mysql-community-server-5.7.37-1.el7.x86_64.rpm mysql-community-test-5.7.37-1.el7.x86_64.rpm [root@hadoop207 software]#
-
按照顺序执行以下
sudo rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm sudo rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm sudo rpm -ivh mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm sudo rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm sudo rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@hadoop207 mysql]# sudo rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm 警告:mysql-community-common-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-common-5.7.37-1.e################################# [100%] [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm 警告:mysql-community-libs-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-libs-5.7.37-1.el7################################# [100%] [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm 警告:mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-libs-compat-5.7.3################################# [100%] [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm 警告:mysql-community-client-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-client-5.7.37-1.e################################# [100%] [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm 警告:mysql-community-server-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-server-5.7.37-1.e################################# [100%] [root@hadoop207 mysql]#
-
安装途中可能会报错,因为我不是第一次安装,所以本次没有报错,一般会出现缺少libao这个依赖的,那就使用以下命令安装libao
yum install -y libaio
-
查看/etc/my.cnf,并删除datadir指向的文件夹下的所有内容,一般第一次安装这里不会有东西
[root@hadoop207 mysql]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [root@hadoop207 mysql]# cd /var/lib/mysql [root@hadoop207 mysql]# rm -rf ./* [root@hadoop207 mysql]#
-
初始化数据库
sudo mysqld --initialize --user=mysql
-
查看刚才初始化临时生成的密码
[root@hadoop207 mysql]# sudo mysqld --initialize --user=mysql [root@hadoop207 mysql]# cat /var/log/mysqld.log 2022-03-17T02:25:58.909440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-03-17T02:25:59.267735Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-03-17T02:25:59.324053Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-03-17T02:25:59.385461Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 953a662d-a599-11ec-8097-000c29033aed. 2022-03-17T02:25:59.388007Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-03-17T02:25:59.797101Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-03-17T02:25:59.797130Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-03-17T02:25:59.797672Z 0 [Warning] CA certificate ca.pem is self signed. 2022-03-17T02:26:00.211341Z 1 [Note] A temporary password is generated for root@localhost: BSw:0iia8Sal [root@hadoop207 mysql]#
-
启动mysql服务
sudo systemctl start mysqld
-
登陆mysql,使用刚才临时生成的密码登陆
[root@hadoop207 mysql]# sudo systemctl start mysqld [root@hadoop207 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.37 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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 root用户密码,并允许root用户在任意ip登陆
mysql> set password = password("root");我的密码就设置成了root Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> update mysql.user set host='%' where user='root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
-
退出mysql,并使用刚设置的密码登陆试试
mysql> exit Bye [root@hadoop207 mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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>
-
ok了
centos7 安装 mysql5.7
于 2022-03-17 11:07:33 首次发布