Table of contents
Compilation of database configuration file [my.ini]
View the MySQL service existing in the computer
Login skip password verification
foreword
In the previous section, we mentioned the relational operations between relational database database data, including basic union, difference, intersection, and Cartesian product operations, as well as complex relational operations such as selection, projection, connection, and division.
In this section, we mainly describe the basic operations of the MySQL database service, such as the opening, closing, and initialization of the MySQL service.
Note: If you have already configured the MySQL database, you can directly read the next chapter!
Database initialization
The initialization here refers to starting from the download of the database compressed package.
Note: Here I put the compressed package of the database in C :\Program Files\mysql-5.7.36-winx64
Add environment variables
This step is essential, I believe you are already very proficient in configuring environment variables.
计算机 --> 属性 --> 高级系统设置 --> 高级 --> 环境变量 --> 系统变量 --> Path
Add the following path to:
C:\Program Files\mysql-5.7.36-winx64\bin
Compilation of database configuration file [my.ini]
After you download the compressed file, you need to write a my.ini configuration file and place it under the C:\Program Files\mysql-5.7.36-winx64 directory:
Note:
1. There was no data folder at the beginning.
2. # in the configuration file represents comments
[mysqld]
port=3306
basedir=C:\\Program Files\\mysql-5.7.36-winx64
datadir=C:\\Program Files\\mysql-5.7.36-winx64\\data
You can also add in the configuration file:
[client]
default-character-set=utf8
To set the default character set of the mysql client.
Note: Every time the my.ini configuration file is modified, the MySQL service must be restarted, otherwise it will not take effect.
Initialize the MySQL service
Note: The following steps are best run under cmd with administrator privileges.
Initialize MySQL (first login)
mysqld --initialize --console
Note: You will be given a string of passwords after execution, which is the initial password, please keep it in mind.
Install MySQL (first login)
mysqld install
Note: After installing MySQL, you need to start the service. If you are in the process of installing MySQL, just look down.
MySQL service operation
If you have installed MySQL, you need to start the service.
If your MySQL service is down. You need to enable the service.
Note: It is best to use a command window with administrator privileges for the following operations.
Install a MySQL service
At this time, there may not be a MySQL service on your computer, so you need to install a MySQL service.
mysqld --install [服务名]
# 例如:mysqld --install mysql
Delete a MySQL service
If you are not satisfied with your MySQL service name, you can delete it.
sc delete [服务名]
# 例如:sc delete mysql
Start your MySQL service
net start [服务名]
# 例如:net start mysql
Note: If the net command is not recognized.
please try:
.\net start [服务名]
Shut down your MySQL service
net stop [服务名]
# 例如:net stop mysql
NOTE: If the net command is not recognized, try:
.\net stop [服务名]
View the MySQL service existing in the computer
(1) Open the task manager
(2) Click on the service in the upper column
(3) Find out if there is a MySQL service in it.
(4) Right-click a service and click to view details
(5) Check whether it is enabled by mysqld.exe:
If yes, the service is the one started by MySQL.
If it is not found, it means that the MySQL service has not been installed in the computer.
other operations
login database
Prerequisite: Open the database service
mysql -h 主机名 -P 端口号 -u 用户名 -p 密码
Shorthand: (directly log in as the root user)
mysql -u root -p
change Password
If you are using the database for the first time, you need to change the password after you start the service, otherwise you cannot use any functions in it.
Method 1: Use mysqladmin.exe (no need to enter MySQL, but need to know the original password)
mysqladmin -u 用户名 -p 旧密码 password 新密码
Method 2: Use SQL statement (need to enter MySQL)
set password for username@localhost = password(newpwd);
# 例如:set password for root@localhost = password(123456);
Note: There are many ways to change the password, only 2 are listed here.
Login skip password verification
The MySQL database supports skipping password verification. It is not that you have to enter the password, but you can enter the database no matter what you enter.
Modify the my.ini configuration file to add:
skip-grant-tables
For example:
Note: After modifying the configuration file, you must restart the service, otherwise it will not take effect.