MySQL 5.7 and above decompressed version configuration and installation

Reference: MySQL 5.7 and above decompressed version configuration and installation


1. Add MYSQL_HOME
2. Add environment variable %MYSQL_HOME%\bin
3. Add configuration file my.ini under %MYSQL_HOME%

[client]
port=3306
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir="C:\Program Files\MySQL\MySQL Server 5.7" MySQL的主目录
datadir="C:\Program Files\MySQL\MySQL Server 5.7/TableData/" #表结构都是存在这里的
character-set-server=utf8
max_allowed_packet=10M

sql-mode="MSSQL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO"

4. Initialize the database ( start cmd as an administrator ) and execute the following commands:

mysqld --initialize --user=mysql --console

    Note: There will be a randomly generated initial password at the end of the console message , write it down (because of special characters, it is easy to remember wrongly, it is best to save the entire message in a notepad, which is useful when changing the password in step 6)


    If the above command fails to run, please use the following command instead:

%MYSQL_HOME%\bin\mysqld --initialize --user=mysql --console

    If still unsuccessful, please check step 2

 

5. Add MySQL to the system service

Start cmd as administrator and        execute the following command

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysqld --install MySQL57 #安装服务
Service successfully installed.

C:\Program Files\MySQL\MySQL Server 5.7\bin>net start MySQL57 #启动MySQL57服务
MySQL57 服务正在启动 .
MySQL57 服务已经启动成功。

If the installation is successful, it will display "Service has been started successfully" or Service successfully installed

 

    If the above command is unsuccessful, you can use the following command instead:

%MYSQL_HOME%\bin\mysqld --install MySQL #安装服务
net start MySQL #启动MySQL57服务

    If the installation is successful, it will display "Service has been started successfully" or Service successfully installed

    If still unsuccessful, please check step 2

 

6. Change the password

C:\WINDOWS\system32>cd C:\Program Files\MySQL\MySQL Server 5.7\bin

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p
Enter password: ************    #这里的密码填写第4步生成的初始密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17-log

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>         #到这里就说明输入的初始密码正确,已经登录到mysql

mysql> set password for root@localhost = password('123456');  #把初始密码修改成123456

    If the initial password here is forgotten, delete all files in the folder corresponding to the datadir configured in my.ini , and then perform step 4 again.

7. Verify that the password is changed successfully

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.17-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> #密码修改成功!Enjoy Yourself!

    At this point, your MySQL 5.7 is installed!

8. Question: mysqld --initialize --user=mysql --console What does this mean? It seems that I installed mysql a year ago and did not encounter it? I recently changed my computer and found out when I followed mysql again, if I don't execute it, it means no startup.

        Author's reply: This is a MySQL version problem. In the past, MySQL initialized a user root without a password by default. MySQL officially considered it insecure.
        This command is an initialization command, which is used to initialize and generate a root user and a random password for your computer environment (the data folder is also generated at this time, and there are a bunch of configuration files in it).
        The advantage of this is that one is safe, and the other is that if your MySQL crashes one day, you can also delete the data folder, and then execute the above command again, so that MySQL is like reinstalling it again!

Guess you like

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