MySQL Community Server installation and configuration tutorial (Windows version)

(1) Understanding MySQL Community Server:

MySQL Community Server is the name of the open source MySQL database service. It is an open source database server launched by MySQL AB in 2000 and is now maintained and managed by Oracle Corporation.

MySQL Community Server is a relational database system that supports multiple types of data and multiple concurrent users. It provides a powerful SQL query language, and an extensible architecture for data management and expansion. In addition to supporting multiple platforms (including Linux, Windows, MAC, and FreeBSD, etc.), MySQL Community Server also supports multiple storage engines (such as InnoDB, MyISAM, etc.), and you can choose different storage engine categories according to different applications.

MySQL Community Server also provides some advanced functions, such as replication, partition, backup and recovery, security, etc., which can provide enterprises with reliable data backup and recovery, and can prevent database security attacks. In addition, MySQL Community Server also supports clustering and rapid response data analysis, and also integrates many other tools and applications to facilitate programmers to better manage and develop MySQL databases.

(2) Get MySQL:

2.1: Go to MySQL official website: https://www.mysql.com/  Click DOWNLOADS:

2.2: Select the version, click MySQL Community (GPL) Downloads, and enter the download page of MySQL Community Edition:

2.3: Click on the MySQL Community Server connection to enter the download page of the MySQL Community Server:

2.4: Download the MySQL installation package:

(3) Install MySQL:

 3.1: Run the Windows command handler as an administrator, and use the command to switch to the bin directory of the MySQL installation directory:

3.2: Use the command to install the MySQL service, the specific installation command is as follows:

(Under the Windows platform, the MySQL service runs in the form of a system service, so you need to register the service through the mysqld -install command. MySQL80 means that the instance name of the MySQL service to be installed is MySQL80. The instance name can be changed according to your needs.)

./mysqld -install MySQL80

When successfully appears, the MySQL service is successfully installed: 

(4) Configure MySQL: 

4.1: Configure and initialize the MySQL service. In the MySQL installation directory, use a text compiler to create a configuration file. Generally, the name of the MySQL configuration file is defined as my.ini:

 4.2: Automatically create the database file directory by initializing MySQL, the specific command is as follows:

./mysqld --initialize --console

./mysqld --initialize --console is a MySQL server command used to create the data directory and system tables when initializing a MySQL database. The following is a description of the parameters of the command:

  • ./mysqld It means to start the MySQL server process, and some parameters can be accepted to configure MySQL, such as setting the data directory, port number, etc.
  • --initialize The parameter indicates to initialize the MySQL database, which will create the MySQL system table and initialize the data directory to prepare for the subsequent use of MySQL.
  • --console The parameter means to output the initialization log in the console, including the temporary password created during the initialization process.

Generally speaking, when you install MySQL for the first time and start the MySQL server, you need to run  ./mysqld --initialize --console the command to initialize the database. This will create a basic data structure for MySQL and prepare a folder for storing data, but a temporary password will be generated during the initialization process, and you need to keep it safe for logging in to MySQL in the future.

(5) Manage MySQL service:

5.1: Start the MySQL service:

net start MySQL80

5.2: Stop the MySQL service:

net stop MySQL80

(6) Log in to MySQL and password settings:

( After the MySQL service is successfully started , you can log in to MySQL and set the password through the MySQL client)

6.1: Log in to MySQL through mysql.exe, the command is as follows:

mysql -h hostname -u username -ppassword

This is a command line command to connect to a MySQL database, mainly used to connect to the MySQL database server by command line.

Among them, the meaning of each parameter is as follows:

  • -h hostname: Specify the hostname or IP address of the MySQL server.
  • -u username: Specify the MySQL user name to connect.
  • -p: Prompt the user for a password. If the password is empty, you don’t need to enter the -p parameter, just follow the -p with a space.
  • password: The password that the user needs to provide.

This command will connect to the MySQL server via the command line, and if successful, the user will be able to execute SQL queries on the command line and interact with the MySQL database. Be sure not to use this command in a public environment since it contains user password information. It is best to use  mysql_config_editor a tool to create and store user credentials.

Here, the blogger’s MySQL is the root user, and the initial password set is “JjbD0v_QeygM” generated when MySQL was initialized to automatically create the database file directory. The command is as follows:

mysql -uroot -pJjbD0v_QeygM

6.2: After successfully logging in with the MySQL client, if you need to exit the MySQL command line client, you can use the exit or quit command.

6.3: The current password of the root user is randomly generated when MySQL is initialized, which is inconvenient to remember. MySQL allows setting passwords for users who log in to the MySQL server. Let’s take setting the password of the root user as an example to set the password of the MySQL account. The specific statements are as follows :

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

This is the SQL statement for changing the MySQL user password, changing the specified user name and the password of the MySQL user connected to the host to the specified new password.

In this example, in the ALTER USER statement  'root'@'localhost' indicates the MySQL user to be modified, where  root is the user's username and localhost is the user's connection host.

IDENTIFIED BY '123456' Indicates that the password of the MySQL user is to be changed to  123456.

Therefore, after executing this SQL statement, root the user  localhost needs to use it as a password when connecting to the MySQL server  123456 . It should be noted that the password here is in plain text, which is not safe. In a production environment, it is recommended to use a more secure password storage method, such as encrypted storage or use a third-party authentication system.

 (7) MySQL built-in command learning:

MySQL provides many built-in commands. In the corresponding manual and help information of MySQL, the help information of MySQL is divided into client information and server information.

7.1: Help information on the client side: After logging in to MySQL, execute the help command to get it.

7.2: Help information on the server: Execute the help contents command to get server-related help information.

(8) Configure environment variables:

In order to facilitate access to common directories and executable files in the command line or programs, and to share configuration information between different applications, configure the bin directory of the MySQL installation directory to the PATH environment variable of the system.

You can use commands to configure environment variables in the Windows command processing program window, run the Windows command processing program as an administrator, and execute the following commands in the Windows command processing window (enter the specific path according to your own situation):

setx PATH "%PATH%;E:\mysql-8.0.33-winx64\bin"

This is a command to set the environment variable PATH in the Windows system. Its function is to add the executable file path of MySQL Server to the PATH environment variable so that the executable file of MySQL Server can be run directly on the command line or in other applications. There is no need to enter the full file path.

Specifically, setx a system command-line tool for setting system-level environment variables. PATH is a predefined environment variable that stores the path to the executable on the system. In this command, %PATH%;E:\mysql-8.0.33-winx64\bin it means to combine the path in the current PATH variable with the path of the MySQL Server executable file, and save it to the system environment variable. Among them, %PATH% represents the value of the current PATH variable.

Therefore, after running this command, the system will  E:\mysql-8.0.33-winx64\bin add the MySQL Server executable file path to the PATH environment variable, so that you can run MySQL Server directly by entering the executable file name on the command line or other applications without Enter the full file path.

Guess you like

Origin blog.csdn.net/weixin_61275790/article/details/131175735