Home > Database > Mysql Tutorial > body text

How to install mysql under centos

藏色散人
Release: 2021-12-02 11:18:34
Original
26191 people have browsed it

How to install mysql under centos: 1. Download and install the official MySQL Yum Repository; 2. Install the MySQL server; 3. Log in to the database; 4. Modify the MySQL default password; 5. Enable remote access to mysql. Can.

How to install mysql under centos

The operating environment of this article: Windows 7 system, Mysql version 5.7.14, Dell G3 computer.

How to install mysql under centos?

CentOS7 installation MySQL (full version)

MariaDB is installed by default in CentOS. This is a branch of MySQL, but for needs, it still needs to be installed in the system. Install MySQL in and overwrite MariaDB directly after the installation is complete.

1 Download and install MySQL official Yum Repository, Mysql version 5.7.14

[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
Copy after login
Copy after login

## Use the above command to directly download the Yum Repository for installation. , about 25KB, and then you can install it directly with yum.

[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
Copy after login
Copy after login

Then start installing the MySQL server

[root@localhost ~]# yum -y install mysql-community-server
Copy after login
This step may take some time. After the installation is completed, the previous mariadb will be overwritten. How long will it take? Depends on personal internet speed.

After the installation is complete, let’s do some configuration of mysql.

2 MySQL database settings

(1) First start MySQL

[root@localhost ~]# systemctl start  mysqld.service
Copy after login
(2) Check the running status of MySQL. The running status is as shown in the figure:

[root@localhost ~]# systemctl status mysqld.service
Copy after login

(3) MySQL has started to run normally at this time, but in order to enter MySQL, you must first find out the password of the root user at this time. You can find the password in the log file through the following command:

[root@localhost ~]# grep "password" /var/log/mysqld.log
Copy after login

(4) Log in to the database with the following command:

[root@localhost ~]# mysql -uroot -p
Copy after login
(5) You cannot do anything at this time, because MySQL must change the password by default before you can operate the database. Use the following command to change the password:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
Copy after login
Replace 'new password' with the password you want to set. Note: The password setting must contain uppercase and lowercase letters and numbers and special symbols (,/';:, etc.), otherwise it cannot be configured. success.

If the following error occurs:

It is thought that the password complexity does not meet the default requirements. Use the following command to view the mysql default password complexity:

SHOW VARIABLES LIKE 'validate_password%';
Copy after login

If you need to change the password complexity, please refer to the following command:

set global validate_password_policy=LOW;
Copy after login

set global validate_password_length=6;
Copy after login

##3 Open Mysql remote access

Execute the following command to enable remote access restrictions (note: the IP enabled by the following command is 192.168.19.128. If you want to enable all, use % instead of IP):

grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
Copy after login

Note: password--is the password you set for your mysql remote login.

Then enter the following two lines of commands

mysql> flush privileges;
Copy after login
You can also exit mysql for this step. Specific reference:

4 、开启防火墙端口,CentOS为firewalld添加开放端口3306,具体是什么参考如下:

    https://i-beta.cnblogs.com/posts?cateId=1653053

5 、更改mysql的语言

首先重新登录mysql,然后输入status:

 可以看到,红色方框处不是utf-8,修改为utf8即可。

因此我们先退出mysql,然后再到/etc目录下的my.cnf文件下修改一下文件内容

cd /etc
Copy after login

 进入文件后,新增四行代码:

 保存更改后的my.cnf文件后,重启下mysql,然后输入status再次查看,你就会发现变化啦

 

 到此CentOS7安装Mysql5.7完毕。

set global validate_password_policy=LOW;

【相关推荐:mysql视频教程

The above is the detailed content of How to install mysql under centos. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template