MySQL installation

MySQL download for all platforms: MySQL download Select the MySQL Community Server version and platform you want.

Note: During the installation process, we need to enable the administrator permission to install, otherwise it will not be able to install due to insufficient permission.


Install MySQL on Linux/UNIX

RPM packages are recommended for installing Mysql on Linux. Mysql AB provides the following RPM packages to download:

  • MySQL – MySQL server. You need this option unless you only want to connect to a MySQL server running on another machine.
  • Mysql-client – The MySQL client program, used to connect to and operate the MySQL server.
  • If you want to compile other MySQL clients, such as Perl modules, you will need to install this RPM package.
  • Mysql-shared-this package contains shared libraries (libmysqlclient.so*) that some languages and applications need to load dynamically, using MySQL.
  • Mysql-bench – benchmarking and performance testing tool for MySQL database server.

MySQL > install MySQL

rpm -qa | grep mysql
Copy the code

If you have installed it, you can choose to uninstall it:

RPM -e mysql// Common deletion mode RPM -e --nodeps mysql// Forcible deletion mode. If other dependent files are displayed when you run the preceding command to delete them, you can use this command to forcibly delete themCopy the code

MySQL installation:

MySQL > install MySQL by using yum on CentOS 7. MySQL > install MySQL by using yum on CentOS 7 Dev.mysql.com/downloads/r…

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
Copy the code

Permission Settings:

chown mysql:mysql -R /var/lib/mysql
Copy the code

Initialize MySQL;

mysqld --initialize
Copy the code

Start the MySQL:

systemctl start mysqld
Copy the code

Check the MySQL running status:

systemctl status mysqld
Copy the code

Note: If we are starting the mysql service for the first time, the mysql server will be initialized first.

Alternatively, you can use MariaDB instead. MariaDB database management system is a branch of MySQL, maintained primarily by the open source community and licensed under the GPL. One reason for the development of the branch was that the community took the branch approach to avoid the potential risk of closing MySQL after Oracle acquired it.

MariaDB is intended to be fully compatible with MySQL, including apis and command lines, making it an easy replacement for MySQL.

yum install mariadb-server mariadb 
Copy the code

The mariadb database commands are:

Mariadb systemctl start mariadb systemctl stop mariadb # Mariadb systemctl restart mariadb Enable mariadb # Enable mariadbCopy the code

Verify MySQL installation

After a successful MySQL installation, some basic tables are initialized, and after the server is started, you can perform a simple test to verify that MySQL is working properly.

Use the mysqladmin tool to get the server status:

Use the mysqladmin command to check the version of the server. On Linux, the binary is in the /usr/bin directory and on Windows, the binary is in C:\mysql\bin.

[root@host]# mysqladmin --version
Copy the code

On Linux this command will output the following results, based on your system information:

Mysqladmin Ver 8.23 Distrib 5.0.9-0, for Redhat - Linux -gnu on i386Copy the code

If no information is displayed after the preceding command is executed, it indicates that Mysql is not installed successfully.


Use MySQL Client to execute simple SQL commands

You can connect to the MySQL server using the MySQL command from the MySQL Client. By default, the MySQL server login password is empty, so this example does not need to enter a password.

The command is as follows:

[root@host]# mysql
Copy the code

Mysql > connect to mysql server

mysql> SHOW DATABASES; + -- -- -- -- -- -- -- -- -- -- + | Database | + -- -- -- -- -- -- -- -- -- -- + | mysql | | test | + -- -- -- -- -- -- -- -- -- -- + 2 rows in the set (0.13 SEC)Copy the code

This section describes how to install Mysql

After Mysql is installed, the default password of user root is empty. You can use the following command to create a password for user root:

[root@host]# mysqladmin -u root password "new_password";
Copy the code

You can now connect to the Mysql server with the following command:

[root@host]# mysql -u root -p
Enter password:*******
Copy the code

Note: the password will not be displayed when you enter it, just enter it correctly.


Install MySQL on Windows

 

Installing MySQL on Windows is relatively easy, and the latest version can be viewed in MySQL Download (for more details: Installing MySQL on Windows).

Click the Download button to enter the Download page. Click No Thanks, just start my Download. Can be downloaded immediately:

 

After downloading, we will unzip the zip package to the corresponding directory. Here I will put the decompressed folder in C:\web\mysql-8.0.11.

Next we need to configure the MySQL configuration file

Open the folder C:\web\mysql-8.0.11 and create the my.ini configuration file in this folder. Edit the my.ini configuration file to configure the following basic information:

[client] # set mysql client's default character set default-character-set=utf8 [mysqld] # set mysql client's default character set Basedir =C:\\web\\mysql-8.0.11 # datadir=C:\\web\\ SQLdata # max_connections=20 # Latin1 character-set = UTF8 Default -storage-engine=INNODB default-storage-engine=INNODBCopy the code

MySQL > start MySQL;

Open CMD command line tool as administrator and switch directory:

CD C: \ web \ mysql - 8.0.11 \ binCopy the code

Initialize the database:

mysqld --initialize --console
Copy the code

After the command is executed, the system displays the default password of user root, for example:

. 2018-04-20T02:35:05.464644z 5 [Note] [my-010454] [Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ ...Copy the code

APWCY5ws&hjQ is the initial password, which you will need to log in later. You can also change the password after logging in.

Enter the following installation command:

mysqld install
Copy the code

To start, enter the following command:

net start mysql
Copy the code

Note: the data directory needs to be initialized in 5.7:

CD C: \ web \ mysql - 8.0.11 \ bin mysqld -- the initialize - insecureCopy the code

After the initialization, run net start mysql to start mysql.


Log on to the MySQL

When the MySQL service is running, you can log in to the MySQL database using the MySQL client tool. First, open the command prompt and enter the following name:

Mysql -h host name -u user name -pCopy the code

Parameter Description:

  • -h: specifies the name of the MySQL host to be logged in to by the client. This parameter can be omitted if you log in to the localhost (localhost or 127.0.0.1).
  • -u: indicates the login user name.
  • -p: tells the server that a password will be used to log in. You can omit this option if the password is empty.

If you want to log in to the local MySQL database, just type the following command:

mysql -u root -p
Copy the code

Press Enter to confirm, if the installation is correct and MySQL is running, you will get the following response:

Enter password:
Copy the code

If the password exists, enter it to log in. If the password does not exist, press Enter to log in. You will see Welcome to the MySQL monitor… “.

Then the command prompt will wait for the command input with mysq> and a blinking cursor. Enter exit or quit to log out.