centos 7 install mysql tutorial through yum

1. Check if it has been installed

1. The following command checks whether it has been installed

rpm -qa | grep -i mysql

If it is found that it has been installed, it needs to be uninstalled and then installed (it is said that such uninstallation is not complete.)

rpm -e mysql  

2. Download and install mysql's yum repo source

 CentOS 7的yum源中默认是没有mysql的,如果想通过yum来安装mysql是无法实现。所以,为了解决这个问题我们首先下载和安装mysql的yum的repo源。
 1、下载yum repo源
wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm

2. Install yum repo source

rpm -ivh mysql57-community-release-el7-7.noarch.rpm

After installation, you can check whether the installation is successful through the following command

ls /etc/yum.repos.d/

You can see that there are two more sources under this path: mysql-community.repo and /etc/yum.repos.d/mysql-community-source.repo
insert image description here

3. Install mysql through yum

1、

 yum install mysql-server

After executing this, you will find that this error is reported:

warning: rpmts_HdrFromFdno: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.

This error is reported because MySQL's GPG has been upgraded and needs to be updated to the latest.
Solved by the following command:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

2、

yum install mysql-devel

3、


 yum install mysql

After going through the above steps, you can confirm whether it is installed through the following command

rpm -qa | grep -i mysql

At the same time, you can also use any of the following command tools to view the status of its services, and shut down/restart operations

# service mysqld status   查看mysql当前的状态

# systemctl status mysqld

# service mysqld stop    停止mysql

# systemctl stop mysqld

# service mysqld restart   重启mysql

# systemctl restart mysqld

# service mysqld start    启动mysql

# systemctl start mysqld

Fourth, connect and use mysql

1. Set the startup to automatically start mysql

systemctl enable mysqld 

2. mysql service

1. Cancel the permission verification.
Since it is just installed and I don’t know the initial password, the permission verification is not done through brute force settings here (it is not recommended to do this online, you can do it yourself to play )

在/etc/my.cnf文件中最后添加一行:

```bash
skip-grant-tables

The function of this sentence is to skip the user authentication of mysql, and then restart mysql:

systemctl restart mysqld

Then directly enter mysql, you can log in to the database without any login parameters and press Enter directly;


2、重新设置密码
通过步骤一,进入到mysql的客户端后,依次执行以下sql语句:

```sql
mysql> use mysql;

mysql> show tables;

select user,authentication_string from user;

update mysql.user set authentication_string=password('这里替换为你自己的密码') where user='root';

flush privileges;

exit;

# 逗号不能少 

3. Enable permission verification
Restore the /etc/my.cnf file, delete or comment out skip-grant-tables, and restart mysql:

systemctl restart mysqld

4. Re-login to log in and use mysql through the command

mysql -h localhost -P 3306 -u root -p

Enter the above command, then press Enter, then enter the password, and then press Enter, you can enter the mysql client, and you can start happy crud data

Guess you like

Origin blog.csdn.net/weixin_46589575/article/details/127044881