MySQL Installation
The MySQL download addresses for all platforms are: MySQL Download . Choose the MySQL Community Server version you need and the corresponding platform.
Note:During installation we need to install with administrator privileges enabled, otherwise the installation will fail due to insufficient permissions.
Installing MySQL on Linux/UNIX
On the Linux platform, it is recommended to use RPM packages to install MySQL. MySQL AB provides the download addresses for the following RPM packages:
- 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 programs, 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 software package contains shared libraries (libmysqlclient.so*) that some languages and applications need to load dynamically to use MySQL.
- MySQL-bench - Benchmarking and performance testing tools for the MySQL database server.
Before installation, we can check whether MySQL is already installed on the system:
rpm -qa | grep mysql
If your system has it installed, you can choose to uninstall it:
rpm -e mysql // 普通删除模式
rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
Install MySQL:
Next we will use the yum command to install MySQL on a CentOS 7 system. Note that in CentOS 7, the MySQL database has been removed from the default program list, so before installation we need to download the Yum resource package from the official website. The download address is:https://dev.mysql.com/downloads/repo/yum/

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 -R mysql:mysql /var/lib/mysql/
Initialize MySQL:
mysqld --initialize
Start MySQL:
systemctl start mysqld
Check the MySQL running status:
systemctl status mysqld
**Note:** If we are starting the mysql service for the first time, the mysql server will first perform initial configuration.
In addition, you can also use MariaDB instead. The MariaDB database management system is a branch of MySQL, mainly maintained by the open-source community and licensed under the GPL. One of the reasons for developing this branch is: after Oracle acquired MySQL, there was a potential risk of making MySQL closed-source, so the community adopted a branching approach to avoid this risk.
MariaDB's goal is to be fully compatible with MySQL, including the API and command line, making it an easy replacement for MySQL.
yum install mariadb-server mariadb
The related commands for the MariaDB database are:
systemctl start mariadb #启动MariaDB systemctl stop mariadb #停止MariaDB systemctl restart mariadb #重启MariaDB systemctl enable mariadb #设置开机启动
Verifying the MySQL Installation
After successfully installing MySQL, some base tables will be initialized. After the server starts, you can verify that MySQL is working properly through a simple test.
Use the mysqladmin tool to obtain the server status:
Use the mysqladmin command to check the server version. On Linux, this binary is located in the /usr/bin directory; on Windows, this binary is located in C:\mysql\bin.
[root@host]# mysqladmin --version
On Linux, this command will output the following result, which is based on your system information:
mysqladmin Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386
If the above command produces no output after execution, it means your MySQL was not installed successfully.
Executing Simple SQL Commands with the MySQL Client
You can use the mysql command in the MySQL Client to connect to the MySQL server. By default, the login password of the MySQL server is empty, so this example does not require entering a password.
The command is as follows:
[root@host]# mysql
After the above command is executed, the mysql> prompt will be output, which means you have successfully connected to the MySQL server. You can execute SQL commands at the mysql> prompt:
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.13 sec)
What to Do After MySQL Installation
After a successful MySQL installation, the default root user password is empty. You can use the following command to create a password for the root user:
[root@host]# mysqladmin -u root password "new_password";
Now you can connect to the MySQL server with the following command:
[root@host]# mysql -u root -p
Enter password:*******
** Note:** When entering the password, it will not be displayed; just enter it correctly.
Installing MySQL on Windows
Installing MySQL on Windows is relatively simpler; the latest version can be MySQL Download downloaded and viewed in (More detailed installation:Installing MySQL on Windows)。


Click
Download
button to enter the download page, click the
No thanks, just start my download.
in the figure below to download immediately:

After downloading, we extract the zip package to the appropriate directory. Here I put the extracted folder in C:\web\mysql-8.0.11 the following directory.
Next we need to configure the MySQL configuration file
Open the folder you just extracted C:\web\mysql-8.0.11 , create a my.ini configuration file in that folder, edit the my.ini file to configure the following basic information:
[client]
# Set mysql client default character set
default-character-set=utf8
[mysqld]
# Set port 3306
port=3306
# Set the MySQL installation directory
basedir=C:\\web\\mysql-8.0.11
# Set the data storage directory for the MySQL database. MySQL 8+ does not require this configuration; the system can generate it itself. Otherwise, it may cause errors.
# datadir=C:\\web\\sqldata
# Allow maximum connections
max_connections=20
# The default character set used by the server is the 8-bit encoded latin1 character set
character-set-server=utf8
# Default storage engine to be used when creating a new table
default-storage-engine=INNODB
Next let's start the MySQL database:
Open the cmd command-line tool as an administrator and switch directories:
cd C:\web\mysql-8.0.11\bin
Initialize the database:
mysqld --initialize --console
After execution is complete, the initial default password for the root user will be output, such as:
...
2018-04-20T02:35:05.464644Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
...
APWCY5ws&hjQ is the initial password, which you will need for subsequent logins. You can also change the password after logging in.
Enter the following installation command:
mysqld install
To start, just enter the following command:
net start mysql
Note: In 5.7, you need to initialize the data directory:
cd C:\web\mysql-8.0.11\bin mysqld --initialize-insecure
After initialization, run net start mysql to start mysql.
Logging In to MySQL
When the MySQL service is running, we can log in to the MySQL database through the client tool that comes with MySQL. First open the command prompt and enter a command in the following format:
mysql -h 主机名 -u 用户名 -p
Parameter Description:
- -h : Specify the MySQL host name the client wants to log in to; when logging in locally (localhost or 127.0.0.1), this parameter can be omitted;
- -u : The username for login;
- -p : Tell the server that a password will be used to log in; if the username and password to log in with are empty, this option can be ignored.
If we want to log in to the local MySQL database, we only need to enter the following command:
mysql -u root -p
Press Enter to confirm. If the installation is correct and MySQL is running, you will get the following response:
Enter password:
If a password exists, enter it to log in; if not, just press Enter to log in. After a successful login, you will see the message Welcome to the MySQL monitor...
Then the command prompt will wait for command input with mysql> plus a blinking cursor. Enter exit or quit to log out.