Install MySQL on yum on Linux/UNIX
It is recommended to use RPM package for installation on Linux platform Mysql, MySQL AB provides the download address of the following RPM package:
- MySQL-MySQL server. You need this option unless you only want to connect to a MySQL server running on another machine.
- MySQL-client- MySQL client program, used to connect to and operate the Mysql server.
- MySQL-devel- Libraries and include files, if you want to compile other MySQL clients, such as Perl modules, you need to install this RPM package.
- MySQL-shared- This package contains shared libraries (libmysqlclient.so*) that some languages and applications need to dynamically load using MySQL.
- MySQL-bench - Benchmark and performance testing tool for MySQL database servers.
Before installation, we can check whether the system comes with MySQL installed:
rpm -qa | grep mysql
If your system has it installed, you can choose to uninstall it:
rpm -e mysql // 普通删除模式 rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
Install the official Version
Next we use the yum command to install MySQL under the Centos7 system. It should be noted that the MySQL database has been removed from the default program list in the CentOS 7 version, so we need to download it from the official website before installation. Yum resource package, the download address is: https://dev.mysql.com/downloads/repo/yum/
Note: We need to enable administrator rights to install during the installation process. Otherwise, the installation will fail due to insufficient permissions.
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update yum install mysql-server
Permission settings:
chown mysql:mysql -R /var/lib/mysql
Initialize MySQL:
mysqld --initialize
Start MySQL:
systemctl start mysqld
View MySQL running status:
systemctl status mysqld
Note: If we start the mysql service for the first time, the mysql server will first perform initial configuration.
Install the community version
In addition, you can also use MariaDB instead. The MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and is licensed under the GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there was a potential risk of MySQL being closed source, so the community adopted a branch approach to avoid this risk.
MariaDB aims to be fully compatible with MySQL, including API and command line, making it an easy replacement for MySQL.
yum install mariadb\-server mariadb
The relevant commands for the mariadb database are:
systemctl start mariadb #启动MariaDB systemctl stop mariadb #停止MariaDB systemctl restart mariadb #重启MariaDB systemctl enable mariadb #设置开机启动
Verify MySQL installation
After successfully installing MySQL, some basic tables will be initialized. After the server starts, you can Verify that MySQL is working properly with a simple test.
Use the mysqladmin tool to get the server status:
Use the mysqladmin command to check the server version. On Linux, the binary file is located in the /usr/bin directory. On Windows, the binary file is located in C :\mysql\bin .
[root@host]# mysqladmin --version
This command on Linux will output the following results, which are based on your system information:
mysqladmin Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386
If no information is output after the above command is executed, it means that your Mysql was not installed successfully.
After Mysql is installed successfully, the default root user password is empty. You can use the following command to create the root user's password:
[root@host]# mysqladmin -u root password "new_password";
Now you can connect to the Mysql server through the following command:
[root@host]# mysql -u root -p *******
Note: When entering the password, the password will not be displayed. Just enter it correctly.