To install MySQL using a compressed archive on an Windows system

  • 2021-10-27 09:34:17
  • OfStack

Recently, I need to do a small verification experiment, and I need to install MySQL. I found that there are many tutorials and bug on the Internet, so I directly translated the process of official website. Note that it is a compressed file, not an installed version, and it can be used directly after decompression. Below, I directly paste the process:

Install MySQL on Windows using compressed document installation

1. Extract files to the installation directory

1) Administrator rights
2) Select the installation location, default C:\ mysql, and specify the installation location through the configuration file
3) Use software decompression. If a home directory is generated by default, please put the sub-files in the home directory in the installation location you specified

2. Create a configuration file

A. Why use configuration files

1) The installation and data directories are different from the default locations
2) You need to customize the server settings

B. File location and name

1) When Windows starts the MySQL service, it looks for configuration files in several places, the Windows director/MySQL
2) File name my. ini/my. cnf, avoid conflicts, use one of them
3) 1 Make sure the my. ini file is readable by MySQL server users

C. File format


 [mysqld]
    # set basedir to your installation path
    basedir=E:/mysql
    # set datadir to the location of your data directory
    datadir=E:/mydata/data

D. Related file location initialization

Initialize MySQL to generate related files

E. Replacement catalogue

Move the original data + start the service every time-datadir command line option

3. Select the MySQL server type

1) mysqld: Support named-pipe support
2) mysqld-debug: Automatic memory allocation check

Support the same storage engine. Use named pipe. Pay attention to shutting down named pipe when shutting down

4. Initialize MySQL (initialize with mysqld)

Assume that% BASEDIR% in your current directory bit configuration file is the MySQL installation directory

A. Initialize the data directory

1) bin\ mysqld--initialize: Contains an expired password and requires you to select a new password
2) bin\ mysqld--initialize-insecure: No root password is generated, assuming you assign a password before using the service
3) If MySQL cannot locate the exact installation directory and data storage directory

(1) Command line: bin/mysqld--default-file=C:\ my.ini--initialize
(2) Configuration files such as 2. C.

B. Specific sequence of behavior when invoking the--initialize/--initialize-insecure option

1) The service checks whether the data directory exists, does not exist, and reports an error
2) Create mysql system database and tables in the data storage directory and server
3) Initialize the system table InnoDB, etc
4) The server creates a 'root' @ 'localhost' superuser and other saved users. You should create a key for the superuser
(1) Using the--initialize option, the server generates a random key and marks it as expired, generating warning
(2) Using--initialize-insecure, no password generated
5) If possible, the server generates secondary tables and files on the server side
6) If--init-file option and the file contains SQL statement, the server executes the statement in the file
7) Quit the server

5. Start the MySQL server

MySQL supports named-pipe/TCP/shared memory communication
A. Open Server Command:% basedir%\ bin\ mysqld "--console
B. Open service:% basedir%\ bin\ mysqld
C. Shutdown service:% basedir%\ bin\ mysqld-u root-p (for password) shutdown

6. Account security settings

Assign a new password to 'root' @ 'localhost' when you initialize successfully, start the MySQL service normally, and log in to the database

A. Start the server, such as 5.
B. Connect to the server:

1) Use--initialize Initial Call Directory: Connect to the database as root and log in using the password generated by the server. If you don't know the password, check the error log
shell > myslq -u root -p
Enter passworld: (Enter the password that has been generated)

2) Using--initialize-insecure:

shell > mysql -u root --skip-password

C. Assign a new password to root after successful connection
mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Precautions:

1) The configuration file is encoded as ANSI

2) The above method needs to open two windows by using command line, one of which indicates the server process after running the service opening command, and the other window inputs the login command to log in the database

3) Enter the SQL statement, need to end with a semicolon, need to set and change the root password after the first login

4) Since individuals do not encounter bug in configuration, if they encounter bug, they can check Baidu error code/official website erro code table

Summarize


Related articles: