1: Download MySQL
Official website: https://dev.mysql.com/downloads/mysql/
Select the corresponding download file. (My computer is 64 bits, so this download is a 64-bit download file)
will not download can search online "" "MySQL official website download, there will be a lot of tutorials, recommend a location:" Https://www.cnblogs.com/pipi-changing/p/5452477.html "
2: Install MySQL
Open the download file to extract to the specified file directory. (I unzip this directory for D:\mysql-5.7.21-winx64)
Open the extracted MySQL file under the root directory to create the My.ini (MySQL config file)
About the My.ini configuration file can be directly Baidu search, the following list only simple configuration
The contents of the My.ini file are as follows:
(It is recommended to copy and paste the following files directly)
Note: The Basedir and datadir paths need to be changed to their own MySQL decompression path, that is, the MySQL file path
- [mysql]
-
- # set MySQL client default character set
-
- default-character-set=utf8
-
- [mysqld]
-
- #设置3306端口
-
- port = 3306
-
- # Set M Ysql installation directory
-
- basedir=d:\mysql-5.7.21-winx64
-
- # Setting the data storage directory for the MySQL database
-
- datadir=d:\mysql-5.7.21-winx64\data
-  &NBSP
- # allow maximum number of connections
-
- max_connections=200
-
- the character set used by the # service side defaults to a 8-bit encoded latin1 character set
-
- character-set-server=utf8
-
- # The default storage engine that will be used when creating a new table
-
- default-storage-engine =innodb
Locate the cmd command prompt, right-click Run as Administrator ( must run as Administrator, or the installation process will be error )
Go to MySQL subdirectory bin
Input: mysqld--install (Install) mysqld--initialize (Initialize) net start MySQL (run)
If there is a problem with the mysqld--install (installation) process, check the configuration file Basedir and DataDir path setup problem,
Mysqld--initialize (initialization) process problems, check the D:\mysql-5.7.21-winx64 root directory to generate a data file,
3: Set MySQL login password
Previous versions of MySQL root account default password is not empty, if you log in with a blank password must be an error.
After the MySQL installation, open the Data folder in the MySQL installation directory, there is a. err file, open with Notepad, you can see that there are lines inside
A temporary password is generated for [email protected]: xxxxxxxx
localhost: The following is the default password, copy this password to log in,
You must reset your password after you have successfully logged in, or you will always be prompted for the following line error.
You must reset your password using the ALTER USER statement before executing this statement.
Perform the following command to reset the password so that it can be used normally. (third is recommended for easy connection of sqlyogent tools)
First type: SET PASSWORD = PASSWORD (' NEW PASSWORD ')
Second type: Alter USER user () identified by "123456";
The third type: ALTER USER ' root ' @ ' localhost ' identified with Mysql_native_password by ' new password ';
Another way to set the MySQL password (this method is not everyone can succeed).
Password Setup steps:
- Save file at the end of the My.ini file by adding "Skip-grant-tables" (Cancel permission settings)
- Restart MySQL Service
- CMD Enter Mysql-bin directory, enter Mysql-u root-p, return, this time do not need a password to login
- Resets the password. Input use MySQL return
- Enter update user set Authentication_string=password ("NewPassword") where user= "root"; (new version of MySQL database password field changed to authentication_string)
- Delete my.ini file End "Skip-grant-tables" Save file
- Restart the MySQL service to log in to the root account with a new password
——————————————— installation is complete ———————————————
You can use the command to view the default installed database:
show databases;
Use MySQL;
Show tables;
Mysql> Show databases;+--------------------+| Database |+--------------------+| information_schema | | mysql | | performance_schema | | sys |+----------- ---------+4 rows in Set (0.01 sec) mysql>
See that the MySQL database is initialized by default, where the user table stores information about MySQL users. We can look at the default MySQL user:
Select user,host,authentication_string from Mysql.user;
Mysql> Select user,host,authentication_string from mysql.user;+------------------+-----------+----------------- --------------------------+| User | host | authentication_string |+------------------+-----------+------------------------------- ------------+| Mysql.infoschema | localhost | *thisisnotavalidpasswordthatcanbeusedhere | | mysql.session | localhost | *thisisnotavalidpasswordthatcanbeusedhere | | mysql.sys | localhost | * Thisisnotavalidpasswordthatcanbeusedhere | | Root | localhost | *27c237a977f4f44d3f551f1a673be14dfd232961 |+------------------+-----------+---------------- ---------------------------+4 rows in Set (0.00 sec) mysql>
The host of administrator root is localhost, which represents only localhost login access. If you want to allow other IP logins to be opened, you need to add a new host. If you want to allow all IP access, you can directly modify the "%"
To create a user:
CREATE USER ' xxh ' @ '% ' identified with Mysql_native_password by ' [Email protected]# ';
# (need to note: mysql8.0 encryption method Modified)
#检查用户
Select User, host, plugin, authentication_string from user\g;
Authorizing a remote database
#授权所有权限
GRANT all privileges on * * to ' xxh ' @ '% ';
#授权基本的查询修改权限, set on demand
GRANT select,insert,update,delete,create,drop,alter on *. * to ' xxh ' @ '% ';
View User Permissions
Show grants for ' xxh ' @ '% ';
Example:
mysql> use mysql;database changedmysql> CREATE USER ' xxh ' @ '% ' identified with Mysql_native_password by ' [Email prote cted]# '; #创建用户 (Note: mysql8.0 encryption modified) Query OK, 0 rows affected (0.07 sec)
Mysql>
To view password encryption methods:
Mysql> Select User, host, plugin, authentication_string from user;+------------------+-----------+---------------- -------+-------------------------------------------+| user | Host | Plugin | authentication_string |+------------------+-----------+-----------------------+----------------------- --------------------+| Xxh | % | Mysql_native_password | *70fd6fb4f675e08ff785a754755b5eba6da62851 | | Mysql.infoschema | localhost | Mysql_native_password | *thisisnotavalidpasswordthatcanbeusedhere | | mysql.session | localhost | Mysql_native_password | *thisisnotavalidpasswordthatcanbeusedhere | | Mysql.sys | localhost | Mysql_native_password | *thisisnotavalidpasswordthatcanbeusedhere | | Root | localhost | Mysql_native_password | *27c237a977f4f44d3f551f1a673be14dfd232961 |+------------------+-----------+-----------------------+------------- ------------------------------+5 rows in Set (0.00 sec) MYSQL>
In addition, if you need to add a new account, or other people outside the computer to access MySQL will also need to set up the built-in account host, for reference: MySQL create user and authorization
Reference from: http://www.cnblogs.com/xiongzaiqiren/p/8970203.html
MySQL Download and installation process