MySQL Installation Steps

本文详细介绍了如何在 CentOS 7.4 上安装 MySQL 5.7,包括移除现有 MariaDB、安装 MySQL 必需的 RPM 包及启动 MySQL 服务的过程,并解决了初始密码检索和远程连接配置问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The steps for installing mysql-communit-5.7 on centos7.4 as following:
At first, remove the mariadb on your centos. You can check how many mariadb packages on OS with command below:
rpm -qa|grep mariadb

mariadb-libs-5.5.56-2.el7.x86_64
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64

Then use rpm -e command to remove them.
rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
rpm -e mariadb-5.5.56-2.el7.x86_64 --nodeps
rpm -e mariadb-server-5.5.56-2.el7.x86_64 --nodeps

Next, we will install mysql packages. After we download installation package from offical website, we got a file named mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar. We could extract it to anywhere. But please remember that we should use root account to install mysql rather than common user. OK, we can find there are a lot of rpm files. And we only install four rpm packages. Follow steps below:
rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm

At last, let's start the mysql service.
[root@localhost kevin]# systemctl start mysqld.service
[root@localhost kevin]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2018-06-09 04:29:46 EDT; 24s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3695 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 3602 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 3697 (mysqld)
CGroup: /system.slice/mysqld.service
└─3697 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jun 09 04:29:00 localhost.localdomain systemd[1]: Starting MySQL Server...
Jun 09 04:29:46 localhost.localdomain systemd[1]: Started MySQL Server.

And then verify if it's running.....
[root@localhost kevin]# netstat -an | grep 3306
tcp6 0 0 :::3306 :::* LISTEN

Oh, one more thing, dont forget to retrive the initial password.
# cat /var/log/mysqld.log
2018-06-09T08:29:37.324687Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-06-09T08:29:38.006584Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-06-09T08:29:38.124151Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-06-09T08:29:38.216176Z 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: 3f71ffb2-6bbf-11e8-9b7f-000c29829cee.
2018-06-09T08:29:38.220202Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-06-09T08:29:38.222647Z 1 [Note] A temporary password is generated for root@localhost: PhR4by=l_Uoi

Oh, it has not been closed. I can't connect to server with root user. So continue to search solution from the reference blog. I checked the user table. The host is "localhost" for root user. Obviously, I can't connect to mysql from remote server.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> update user set host = "%" where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

But I still can't connect to the server. All right, finally, at the end of blog, I find solution, flush the cach.
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Bing go!!!

Reference:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值