Download and configuration tutorial of MySQL installation free version

Keywords: Database MySQL

Download and configuration tutorial of MySQL installation free version

There is a previous version of this blog. If readers are still interested in the author's previous version of the blog, you can visit this link: https://blog.csdn.net/wangpaiblog/article/details/111938395

[description]

  • This tutorial describes the download and configuration of MySQL installation free version under Windows. This is often the preference of users who like to execute MySQL code from CMD or want to download files as small as possible. If readers are different from them and prefer to stand on the shoulders of giants, they can choose an integrated IDE to avoid the cumbersome operations described in this tutorial. For this content, you can see another blog of the author:

    MySQL Community installation tutorial:
    https://blog.csdn.net/wangpaiblog/article/details/112000033

  • For MySQL installation under Linux, see another blog of the author:

    MySQL installation tutorial under Linux:
    https://blog.csdn.net/wangpaiblog/article/details/120259448

Author's environment:

  • MySQL 8.0.27

  • Windows 10 Education

  1. Open the official MySQL website and find the download of community version. Community was chosen because it is free and is a commonly used version. The specific process is shown in the following picture.

    The official website of MySQL is: https://www.mysql.com/

    The final website of MySQL Download: https://dev.mysql.com/downloads/mysql/

  2. Unzip the downloaded mysql-8.0.27-winx64.zip to get the MySQL installation directory. The installation directory should be a directory containing the bin folder. In the author's Windows, the paths are as follows:

    • MySQL installation directory: D:\mysql-8.0.27-winx64
    • MySQL command directory: D:\mysql-8.0.27-winx64\bin
    • MySQL database data storage directory: D:\mysql-8.0.27-winx64\data
    • MySQL port number: 3306
  3. Create a MySQL configuration file my.ini in the MySQL directory. This configuration file is used to specify the parameter information of MySQL service process.

    [mysql]
    # Set MySQL client default character set
    default-character-set=utf8 
    
    [mysqld]
    #Set MySQL port number
    port = 3306 
    #skip-grant-tables
    # Set MySQL installation directory
    basedir=D:\mysql-8.0.27-winx64\
    # Set the storage directory of MySQL database data
    datadir=D:\mysql-8.0.27-winx64\data
    # Maximum connections allowed
    max_connections=200
    # The character set used by the server
    character-set-server=utf8
    # The default storage engine that will be used when creating new tables
    default-storage-engine=INNODB
    
    [client]
    #default_character_set=utf8
    
  4. Generally speaking, you only need to modify the port, MySQL installation directory basedir and MySQL data storage path datadir in the above configuration file my.ini.

  5. Run CMD as administrator. If you do not run as an administrator, an error Install/Remove of the Service Denied! Will be reported!.

  6. There are many ways to run CMD as an administrator. Here is just one example.

    1. Use the following command to find the path of CMD, then right-click and select run as administrator. Usually, the path of CMD is located at C:\Windows\System32\cmd.exe.

      where cmd
    2. In this way, the CMD window is opened. There should be the word administrator on the window. The current path displayed in the window is C:\Windows\system32.

    3. Use the following command to enter the disk where MySQL is located.

      d:
      C:\Windows\system32>d:
      
      D:\>
      
    4. Use the following command to enter the MySQL installation path.

      cd mysql-8.0.27-winx64\bin
      D:\>cd mysql-8.0.27-winx64\bin
      
      D:\mysql-8.0.27-winx64\bin>
      

      [prompt]

        if only one MySQL is installed on the computer, you can choose to set the environment variable Path to avoid these troubles. Like many applications, setting environment variables is not necessary, but it can avoid entering the bin directory before entering commands every time.

        the method of setting Windows environment variables can be found in another blog of the author: https://blog.csdn.net/wangpaiblog/article/details/113532591 . Here, the variable value to be set in the environment variable Path is D:\mysql-8.0.27-winx64\bin.

  7. Now, you should enter the MySQL command directory as an administrator in CMD. Enter the command mysqld install mysqlxxx to register the MySQL service in the operating system, where mysqlxxx can be named arbitrarily.

    mysqld install mysql01
       D:\mysql-8.0.27-winx64\bin>mysqld install mysql01
       Service successfully installed.
       
       D:\mysql-8.0.27-winx64\bin>
    
  8. At this point, you should be able to see the MySQL service just registered in Windows.

  9. After the above configuration file is edited. Use the following command to initialize the MySQL directory.

    mysqld --initialize
    D:\mysql-8.0.27-winx64\bin>mysqld --initialize
    
    D:\mysql-8.0.27-winx64\bin>
    
  10. Use the command net start mysqlxxx to start the MySQL service. Where mysqlxxx is the MySQL service name from above.

    net start mysql01
    D:\mysql-8.0.27-winx64\bin>net start mysql01
    mysql01 The service is starting .
    mysql01 The service has been started successfully.
    
    
    D:\mysql-8.0.27-winx64\bin>
    

    [pit stepping reminder]

      if the service cannot be started here, please check:

    • Is the MySQL installation directory in the previous configuration file set correctly
    • Is the MySQL database data storage directory in the previous configuration file set correctly
    • Is the port number set in the previous configuration file occupied
  11. Use the command mysql -u root -p -Pxxx to enter the MySQL database. Where xxx is the port number previously set in the configuration file.

    mysql -u root -p -P3306
  12. The password will be prompted here. This password is generated when the command mysqld --initialize is executed. It is in the file computer name. err in the database data storage directory set earlier. The specific method is to open the file with notepad and find a line with password A temporary password is generated for root@localhost :. This text is followed by the generated random password (this password does not contain spaces). Enter the password to enter the database.

    D:\mysql-8.0.27-winx64\bin>mysql -u root -p -P3306
    Enter password: ******
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.27 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    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>
    

    [pit stepping reminder]

      if the above command omits the parameter - Pxxx, it is equivalent to providing the MySQL default port number 3306. If this is inconsistent with the settings in the previous configuration file, this will cause the following error:

    ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)
    
  13. The password needs to be changed after the initial login. The command to change the password is: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new password';. Among them, the new password shall be replaced with the password set by yourself, and the new password shall be in single quotation marks.

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'helloworld';
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'helloworld';
    Query OK, 0 rows affected (0.02 sec)
    
    mysql>
    

    [pit stepping reminder]

      in MySQL 5.7 and earlier versions, the command to change the password is set password for root@localhost =password('New password ');. If you use this command in MySQL 8.0, the following errors will occur:

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password('helloworld')' at line 1
    
  14. After MySQL login is successful, you can use MySQL language to control the database entry.

  15. After using the database, you can consider exiting. To exit MySQL, first use the command exit to exit the login.

    exit
    mysql> exit
    Bye
    
    D:\mysql-8.0.27-winx64\bin>
    
  16. Use the command net start mysqlxxx to exit the MySQL service. Where mysqlxxx is the MySQL service name from above.

    net stop mysql01
    D:\mysql-8.0.27-winx64\bin>net stop mysql01
    mysql01 The service is stopping.
    mysql01 Service stopped successfully.
    
    
    D:\mysql-8.0.27-winx64\bin>
    

    [prompt]

      if readers love cleaning, you can remove the previously registered MySQL service here. Use the command sc delete mysqlxxx. Where mysqlxxx is the MySQL service name from above.

    sc delete mysqlxxx
    D:\mysql-8.0.27-winx64\bin>sc delete mysql01
    [SC] DeleteService success
    
    D:\mysql-8.0.27-winx64\bin>
    

        however, after doing so, when logging in next time, you need to execute the previous command mysqld install mysqlxxx to install MySQL service again. (at this time, you only need to register the MySQL service and do not need to perform MySQL initialization.)

  17. After exiting, if you need to log in again, just start with the previous command net start mysqlxxx. Examples are as follows:

    D:\mysql-8.0.27-winx64\bin>net start mysql01
    mysql01 The service is starting .
    mysql01 The service has been started successfully.
    
    
    D:\mysql-8.0.27-winx64\bin>mysql -u root -p -P3306
    Enter password: ******
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.27 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    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>
    
  18. Now, the configuration of MySQL installation free version is completed.

Posted by infratl on Fri, 26 Nov 2021 14:56:22 -0800