English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The download address for MySQL on all platforms is: MySQL Download . Select the one you need MySQL Community Server Version and corresponding platform.
Note:We need to install through administrator privileges during the installation process, otherwise the installation will fail due to insufficient permissions.
It is recommended to use RPM packages to install Mysql on Linux platforms, MySQL AB provides the following RPM package download addresses:
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 on the Mysql server.
MySQL-devel - Databases 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 includes shared libraries (libmysqlclient.so) that some languages and applications need to dynamically load.*) Use MySQL.
MySQL-bench - Benchmark and performance testing tools for MySQL database servers.
Before installation, we can check if MySQL is pre-installed on the system:
rpm -qa | grep mysql
If your system is installed, you can choose to uninstall:
rpm -e mysql // Normal delete mode rpm -e --nodeps mysql // Force delete mode, if there are other dependent files when using the above command to delete, you can use this command to delete them forcibly
Install MySQL:
Next, we will install MySQL on Centos7 Use the yum command to install MySQL on the system, it should be noted that CentOS 7 The MySQL database has been removed from the default program list in this version, so we need to download the Yum resource package from the official website before installation, 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 mysql:mysql -R /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 the initial configuration.
In addition, you can also use MariaDB instead. MariaDB database management system is a branch of MySQL, mainly maintained by the open source community and licensed under GPL. One of the reasons for developing this branch is that after Oracle Corporation acquired MySQL, there is a potential risk of MySQL being closed source, so the community adopts the branch method to avoid this risk.
The purpose of MariaDB is to be fully compatible with MySQL, including API and command line, making it easy to become a substitute for MySQL.
yum install mariadb-server mariadbThe relevant commands for mariadb database are:
systemctl start mariadb # Start MariaDB systemctl stop mariadb # Stop MariaDB systemctl restart mariadb # Restart MariaDB systemctl enable mariadb # Set to boot
After successfully installing MySQL, some basic tables will be initialized. After the server starts, you can perform simple tests to verify that MySQL is working properly.
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 at /usr/bin directory, on Windows, the binary file is located at C:\mysql\bin.
[root@host]# mysqladmin --version
The mysqladmin command will output the following results on Linux, 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 executing the above command, it means that your Mysql has not been installed successfully.
You can use the mysql command to connect to the MySQL server using the MySQL Client (MySQL client). By default, the login password of the MySQL server is empty, so no password needs to be entered in this example.
The command is as follows:
[root@host]# mysql
After executing the above command, the mysql> prompt will appear, indicating 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)
After Mysql is installed, the default root user password is empty, you can create a password for the root user using the following command:
[root@host]# mysqladmin -u root password "new_password";
Now you can connect to the Mysql server using the following command:
[root@host]# mysql -u root -p Enter password:*******
Note:When entering a password, the password will not be displayed, just make sure you enter it correctly.
Installing MySQL on Windows is relatively simple, the latest version can be found at MySQL Download Downloading and viewing in Chinese.More detailed installation:MySQL installation on Windows)。
click Download button to enter the download page, click the No thanks, just start my download. and you can download it immediately:
After downloading, we will unzip the zip package to the corresponding directory, here I will place the unzipped folder in C:\web\mysql-8.0.11 .
Next, we need to configure the MySQL configuration file
Open the folder just unzipped C:\web\mysql-8.0.11 Create a new file in this folder. my.ini Configuration file, edit my.ini Configure the following basic information:
[client] # Set the default character set for the mysql client default-character-set=utf8 [mysqld] # Set3306Port port = 3306 # Set the installation directory of mysql basedir=C:\\web\\mysql-8.0.11 # Set the storage directory for the data of the mysql database, MySQL 8+ # The following configuration is not required, the system will generate it automatically, otherwise it may report an error # datadir=C:\\web\\sqldata # The maximum number of connections allowed max_connections=20 # The default character set used by the server is8latin encoded in bits1Character set character-set-server=utf8 # The default storage engine 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, switch to the directory:
cd C:\web\mysql-8.0.11\bin
Initialize the database:
mysqld --initialize --console
After the execution is completed, 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 is required for subsequent login, and you can also change the password after login.
Enter the following installation command:
mysqld install
Start by entering the following command:
net start mysql
Note: In 5.7 It is necessary to initialize the data directory:
cd C:\web\mysql-8.0.11\bin mysqld --initialize-insecureAfter initialization, running 'net start mysql' will start mysql.
When the MySQL service is running, we can log into the MySQL database using the MySQL built-in client tool. First, open the command prompt and enter the following command format:
mysql -h Hostname -u Username -p
Parameter Description:
-h : Specify the hostname of the MySQL client to log in. Log in to the local machine (localhost or 127.0.0.1) This parameter can be omitted;
-u : The username to log in;
-p : The server will use a password to log in. If the username and password to log in are empty, this option can be ignored.
If we want to log in to the MySQL database on this machine, we just 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 the password to log in; if not, press Enter to log in directly. After successful login, you will see the prompt 'Welcome to the MySQL monitor...'.
Then the command prompt will keep waiting for the input with a blinking cursor after mysq> until a command is entered. exit or quit Log out.