MySQL download addresses of all platforms are: MySQL Download . Select the MySQL Community Server version and corresponding platform you need.
Note: during the installation process, we need to enable the administrator permission to install, otherwise the installation will not be possible due to insufficient permission.
Installing MySQL on Linux/UNIX
It is recommended to use RPM package to install MySQL on Linux platform. MySQL AB provides the following download address of 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, which is used to connect to and operate the Mysql server.
- MySQL devel - Library and include files. If you want to compile other MySQL clients, such as Perl modules, you need to install the RPM package.
- MySQL shared - this package contains a shared library (libmysqlclient.so*) that needs to be dynamically loaded for some languages and applications. MySQL is used.
- MySQL bench - benchmark and performance test tool for MySQL database server.
Before installation, we can check whether the system comes with MySQL:
rpm -qa | grep mysql
If your system is installed, you can choose to uninstall:
rpm -e mysql // Normal delete mode rpm -e --nodeps mysql // Strong delete mode: if you use the above command to delete, you will be prompted that there are other dependent files, and you can use this command to delete them
To install MySQL:
Next, we use the yum command to install MySQL on the Centos7 system. It should be noted that the MySQL database in the CentOS 7 version has been removed from the default program list, so we need to download the yum resource package on the official website before installing. The download address is: MySQL :: Download MySQL Yum Repository
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
chown -R mysql:mysql /var/lib/mysql
systemctl start mysqld
To view MySQL running status:
systemctl status mysqld
Note: if we start the mysql service for the first time, the mysql server will be initialized first.
In addition, you can also use MariaDB instead. MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and licensed by GPL. One of the reasons for developing this branch is that after Oracle acquired mysql, there is a potential risk of closing the source of MySQL. Therefore, the community adopts the branch method to avoid this risk.
MariaDB aims to be fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL.
yum install mariadb-server mariadb
The related commands of mariadb database are:
systemctl start mariadb #Start MariaDB systemctl stop mariadb #Stop MariaDB systemctl restart mariadb #Restart MariaDB systemctl enable mariadb #Set startup
Verify MySQL installation
After MySQL is successfully installed, some basic tables will be initialized. After the server is started, you can verify whether MySQL works normally through simple tests.
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, and on Windows, the binary file is located in C:\mysql\bin.
[root@host]# mysqladmin --version
On linux, this command 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, your Mysql installation is not successful.
Use the MySQL client to execute simple SQL commands
You can use the MySQL command to connect to the MySQL server in the MySQL Client(Mysql client). By default, the login password of the MySQL server is empty, so this instance does not need to enter a password.
The command is as follows:
After the above commands are executed, the Mysql> prompt will be output, which indicates that 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 Mysql is successfully installed, the default root user password is blank. You can use the following command to create the root user 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 Enter password:*******
Note: when entering the password, the password will not be displayed. You can enter it correctly.
Installing MySQL on Windows
It is relatively easy to install MySQL on Windows. The latest version can be installed on the MySQL Download View in download
Click the download button to enter the download page, and click No thanks, just start my download Download Now:
After downloading, we unzip the zip package to the corresponding directory. Here, I put the unzipped folder under C:\web\mysql-8.0.11.
Next, we need to configure the MySQL configuration file
Open the folder just extracted C:\web\mysql-8.0.11, and create my Ini configuration file, edit my Ini configure the following basic information:
[client] # Set mysql client default character set default-character-set=utf8 [mysqld] # Set 3306 port port = 3306 # Set the mysql installation directory basedir=C:\\web\\mysql-8.0.11 # Set the storage directory of mysql database data. MySQL 8+ does not need the following configuration. The system can generate it by itself. Otherwise, errors may be reported # datadir=C:\\web\\sqldata # Maximum connections allowed max_connections=20 # The character set used by the server defaults to the 8-bit encoded latin1 character set character-set-server=utf8 # Default storage engine to use when creating new tables default-storage-engine=INNODB
Next, let's start the MySQL database:
Open the cmd command line tool as an administrator to switch directories:
mysqld --initialize --console
After execution, the initial default password of 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 is required for subsequent login. You can also change the password after login.
Enter the following installation command:
Start and enter the following command:
net start mysql
Note: the data directory needs to be initialized in 5.7:
cd C:\web\mysql-8.0.11\bin mysqld --initialize-insecure
After initialization, run net start mysql to start mysql.
Log in to MySQL
When the MySQL service is running, we can log in to the MySQL database through the built-in client tools of MySQL. First, open the command prompt and enter the following format:
mysql -h host name -u user name -p
- -h: specify the MySQL host name to be logged in by the client. This parameter can be omitted when logging in to the local machine (localhost or 127.0.0.1);
- -u: login user name;
- -p: tell the server that a password will be used to log in. If the user name and password to log in 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 that if the installation is correct and MySQL is running, you will get the following response:
If the password exists, enter the password to log in. If it does not exist, directly press enter to log in. You will see Welcome to the MySQL monitor Prompt for.
Then the command prompt will always wait for the command input with mysq> and a flashing cursor, and enter exit or quit to exit the login.