Install MySQL using an installation-free tarball

OS: Windows 10 Home Chinese version MySQL: mysql-5.7.20-winx64.zip

Author: Ben.Z

Reference link:

Installing MySQL on Microsoft Windows

Installing MySQL on Microsoft Windows Using a noinstall ZIP Archive

 

Let me talk about the history of my installation of MySQL:

At first, it was installed with a Windows executable file. After installation, use the MySQL notifier to turn on and off the service;

Later, I learned to install the installation-free version (noinstall). After downloading the compressed package, Baidu searched for "how to install the installation-free version of MySQL", and then based on what others wrote.

Chinese data Install MySQL, then use the NET command to start and stop the service or start and stop the setting service in the service controller;

This time it is also a free installation version, but the difference is that there is no Baidu to find information, but MySQL is installed step by step according to the installation steps of the MySQL official website (English), and finally, MySQL installation

It worked, and set the MySQL server to start and stop randomly (Starting MySQL as a Windows service) .

 

The installation steps are as follows:

-Download MySQL Free Installer

A zip file, I downloaded mysql-5.7.20-winx64.zip;

- Unzip the installation-free version, and put the unzipped folder in the location you specify

The decompressed folder is the main directory of MySQL, change the folder name to mysql (you are free), and then place it in the location you specify - mine is D:\p

- Open the README in the mysql directory and find the installation instructions

View the README file, you can find information on how to install MySQL, and then open the corresponding installation instructions (For installation instructions...) to install MySQL step by step;

-Open the webpage 2.3.5, then follow the steps inside to install the MySQL free installation version, and finally set the MySQL service as a Windows service

As can be seen from the figure below, the MySQL official website gives 9 steps, of which 2.3.5.2 and 2.3.5.4 are the keys. The following describes the key steps in the installation process;

-2.3.5.2 Creating an Option File

This section describes the creation of a MySQL configuration file: when MySQL starts, the MySQL server is set up according to the contents of this configuration file.

The webpage said that when MySQL starts, it will look for configuration files in two places: the WINDOWS directory and the MySQL installation directory.

Among them, the WINDOWS directory is generally "C:\WINDOWS", which can be found by using echo %WINDIR% on the command line. The MySQL installation directory is the one we used earlier.

Unzip the resulting directory.

The name of the configuration file is my.ini or my.cnf. However, my.ini has a higher priority than my.cnf and is a text file.

The essential! The configuration in the files with the two names in the two places where the configuration files are placed will be read and used to configure MySQL. To avoid confusion, please put all configurations

It is written to a file and placed in a directory.

I wrote the configuration information to the my.ini file and put it in the MySQL installation directory.

Next, enter the content in the Option File file. In this page, there are two configuration items that need to be entered: basedir, datadir , basedir represents the MySQL installation directory

directory, datadir indicates the data storage directory of the MySQL database.

Note that the path separator for Windows is [slash] , you need to replace it with [backslash] , or replace each slash with two slashes.

Note that the data directory needs to be created manually. I created the data folder in the MySQL installation directory, which is empty.

Question: Do you want to create an Option File? Can't build it? Can basedir or datadir not be set up?

My config file is as follows:

For more configuration options, see Server Configuration Defaults and the linked pages there.

 -Initializing the Data Directory

The location datadir of the data folder is specified in the configuration file, but the newly created data folder is empty, at this time, it needs to be initialized.

MySQL official website guide: 2.9.1.1 Initializing the Data Directory Manually Using mysqld

Note that Windows administrator privileges are required to perform this operation.

Open the Windows command line tool with administrator privileges and enter the MySQL installation directory;

Two commands are given in the official guide 2.9.1.1: --initialization, --initialization-insecure. From the literal meaning, the former is secure and the latter is not secure.

The --initialization command will create a random password for the 'root'@'localhost' account after initialization, while the --initialization-insecure command will create a random password for the 'root'@'localhost' account

Empty password, and it will not expire ( it turns out that the MySQL I installed before was insecure! ).

I choose --initialization command , execution method and result:

After the execution completes, no results are displayed in the command line.

However, a lot of new folders and files have been created in the data directory at this time.

I just said that using --initialization will create a random password for the 'root'@'localhost' account, so where is this random password? See the picture above? have inside

A file ending with .err , the random password is in it; after the server is started, you can use the root account and this password to log in;

At this point, the initialization of the data file is completed.

In the official guidance file, there are more initialization commands to choose from, such as --user, --defaults-file, --console...

- Start the MySQL server for the first time

After the previous configuration file is written and the data directory is initialized , the MySQL server can be started.

Various commands of MySQL are found in the bin directory under the installation directory: mysql, mysqld, mysqldump, mysqladmin... (I used it)

In this section, the MySQL server is started using the mysqld command, which can be started by executing the following command:

mysqld.exe --console

However, --console can be omitted, the purpose of using it is to see log messages directly on the command line.

The default port for MySQL is 3306. As you can see from the image below, the MySQL server is up and ready to accept connections.

After the MySQL server starts, you can see it in the Windows Task Manager:

 

Note that the Windows security alarm serial port will appear when the MySQL server is started, click the "Allow Access" button.

 

Note that error log records are generated during MySQL operation, and these error log records will be stored in files ending with *.err in the data directory. Of course, the file that records the error log

It can also be set when the mysqld command starts the server, and the setting is executed as --log-error.

 

When starting the server with the mysqld command, you can also enter the following command:

--standalone

--debug

--shared-memory (requires deeper understanding)

 

All options supported by the mysqld command can be output by the following command ( note that there is a lot of content and can be output to a file):

mysqld --verbose --help

verbose: adj., verbose, long-winded

 

MySQL server shutdown method: use the mysqladmin command

mysqladmin -u root shutdown

However, I use Ctrl+C to stop the server running.

 

- Connect to a running MySQL server

This article uses the mysql command to connect to it from the Windows command line.

Open the Windows command line, enter the MySQL installation directory, and use the mysql.exe command in the bin directory to connect to the running server.

Enter the following command:

bin\mysql.exe -uroot -p

Then enter the root password to log in to the server.

As mentioned earlier, what is the root password, which is described earlier in this article.

Use the show databases; command to view the databases in the server: failed! Forcibly change the password of the root account!

After the modification is completed, use show databases again; you can see the list of currently existing databases. Only 4 databases exist. What is the use of each one, it needs to be introduced separately.

View the account information of the database server: it exists in the user table of the mysql database. There are only 3 accounts during initialization, root is one of them, and the other two are not used.

 

For more MySQL operations and how to use commands, please read the relevant tutorials!

 

- Add MySQL operation commands to the Windows environment variable PATH

When using MySQL commands earlier, we all need to enter the path of the command, so it is very inconvenient to enter the MySQL bin directory from the command line!

In order to use the command directly in the command line tool, therefore, add the MySQL bin directory to the Windows environment variable PAH.

Note that the environment variable PATH is Path on my computer.

Note that the add windows of different Windows operating systems are different, the Windows 10 is as shown below.

After the MySQL command is added to the environment variable PATH, it can be tested, and this time I was successful.

 

At the end of the official guide, it is proposed that if multiple MySQLs are installed on the computer, it is not recommended to add MySQL commands to the PATH, and do not add one to avoid conflicts.

Of course, such a computer must be a programmer's computer, a development computer.

 

- Install MySQL server as a Windows service and start randomly

This is also the last step in this article.

Official guide: 2.3.5.8 Starting MySQL as a Windows Service

It is very clear in the official guidance, and now I will introduce it in my way of expression.

MySQL is installed as a Windows service so that it starts randomly and can also be managed using the command NET or the graphical tool Service Manager.

Note that the following operations require the use of a Windows command line opened as an administrator .

Note , please stop the MySQL server before setting.

 

To perform this step, you need to use the mysqld command, open the command line as an administrator, and enter the mysqld -install command to complete the installation;

After the installation is complete, you can see MySQL under the Windows service manager, the startup type is "automatic", and the status is empty - stop.

Automatic means that the MySQL server will start after Windows boots, no manual action is required.

 

Now, start the MySQL server. Two ways: NET command, start in Windows Service Manager. The following figure shows the NET command mode.

If the startup is successful, you can see that the status of the MySQL service is "running" in the service manager, or you can connect to it through the client;

 

At this point, the MySQL server is installed, please use it! Feel free to use Python to connect test development!

 

In the official guide, other parameters can be added to install MySQL as a Windows service, for example, --install specifies the server name, --defaults-file, --local-service, etc.

The default name of the MySQL service installed with --install is MySQL, which can be modified.

The specific meaning of the parameters can be found in the official guidance document.

 

In addition, the MySQL service installed with the --install parameter is started randomly, and it can also be installed manually with the --install-manual parameter .

 

Comments: hey

This time, I have gained a lot from installing MySQL according to the official instructions. I used to refer to some Chinese materials to install it, but I always felt uneasy.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325296746&siteId=291194637