Database foundation - 2. MySQL uninstallation and installation and related environment configuration

In this article, we will talk about the download, installation, related environment configuration, possible problems and solutions, uninstallation and other operations of MySQL.

Table of contents

1. View the installed

1.1 View in the command prompt window

1.2 View in the file directory

2. Uninstall Mysql

2.1 uninstall mysql

 2.2 Clean up other files

3. MySQL download

3.1 Introduction

3.2 Software download

3.3 Software installation

3.4 Mysql configuration

3.4 Installation of MySQL5.7 version

4. Possible problems of installation failure

5. MySQL login

5.1 Start and stop of service

5.2 Login and logout of built-in client

6. MySQL demo

6.1 Demonstration of the use of MySQL

6.2 MySQL encoding settings

7. MySQL graphical management tool

7.1 Tools 1. MySQL Workbench

7.2 Tools 2. Navicat

8. MySQL source code and directory

8.1 MySQL directory

8.2 MySQL source code acquisition

 9. Other issues

9.1 Question 1: I forgot the root user password, how to reset it

9.2 Question 2: The mysql command reports "not an internal or external command"

9.3 Question 3: The character set problem of the command line client 


1. View the installed

1.1 View in the command prompt window

First, let's check the version and information of MySQL installed on this machine

Enter the command prompt window

Enter: mysql --version to view the version of mysql

Enter: mysql -uroot -p to enter the installed database

 1.2 View in the file directory

 This is the directory where my mysql is installed

This is the root directory of mysql (the root directory of all software is at the bin level) , and the data folder contains the library and tables in the library we built in the database. The my.ini file is the configuration of mysql files are also important

2. Uninstall Mysql

Let's talk about how to uninstall Mysql

2.1 uninstall mysql

 Method 1: Delete the folder directly (violent uninstall)

Of course, this method is not recommended, because there will be residual registry and other files

Method 2: Uninstall through the control panel

To uninstall the MySQL8.0 program, you can directly select “Uninstall a Program” in the “Control Panel” like other desktop applications , and find the MySQL8.0 server program in the program list, and double-click to uninstall it, as shown in the figure. In this way, the data in the data directory will not be deleted. 

Method 3: Uninstall through 360 or computer housekeeper

slightly

Method 4: Uninstall via the installer

You can also uninstall through the installer.

① Double-click the downloaded mysql-installer-community-8.0.26.0.msi file again to open the installation wizard. The installation wizard will automatically detect the installed MySQL server program.

② Select the MySQL server program to be uninstalled, and click "Remove" to uninstall. 

 ③ Click the "Next" button to confirm the uninstallation.

 ④ A selection window pops up whether to remove the data directory at the same time. If you want to delete the data in the MySQL server at the same time, check "Remove the data directory", as shown in the figure.

⑤ Execute uninstallation. Click the Execute button to uninstall.

⑥ Complete the uninstallation. Click the "Finish" button and that's it. If you want to uninstall the installation wizard program of MySQL8.0 at the same time, check "Yes, Uninstall MySQL Installer", as shown in the figure. 

 2.2 Clean up other files

Cleanup of leftover files

If the reinstallation is unsuccessful, you can uninstall and clean up the remaining files before reinstalling.

  1. Service directory: the installation directory of the mysql service
  2. Data directory: C:\ProgramData\MySQL by default

If you have specified the data directory separately, you can find your own data directory and delete it.

Note: Please make a data backup before uninstalling. After the operation is completed, you need to restart the computer and then install it. If the installation still fails, you need to continue as follows, that is, to clean the registry

Clean up the registry (optional)

If you have done the previous steps and the installation still fails, you can clean up the registry. How to open the Registry Editor: Type regedit in the system's search box

Delete the configuration of environment variables

Find the path environment variable, and delete the environment variable about mysql, remember not to delete them all.

For example: delete D:\develop_tools\mysql\MySQLServer8.0.26\bin; this part 

 Note: Be sure to restart the computer after cleaning

3. MySQL download

3.1 Introduction

  • MySQL Community Server community version, open source and free, free to download, but does not provide official technical support, suitable for most ordinary users.
  • MySQL Enterprise Edition The enterprise version requires payment and cannot be downloaded online. You can try it for 30 days. It provides more functions and more complete technical support, and is more suitable for enterprise customers who have higher requirements for database functions and reliability.
  • MySQL Cluster cluster version, open source and free. It is used to set up a cluster server, and several MySQL Servers can be packaged into one Server. It needs to be used on the basis of Community Edition or Enterprise Edition.
  • MySQL Cluster CGE Premium Cluster Edition, for a fee.

The current latest version is 8.0.27 , which will be released in October 2021. Previously, 8.0.0 was released on September 12, 2016. 

In addition, the official also provides MySQL Workbench (GUITOOL), a graphical interface management tool specially designed for MySQL . MySQLWorkbench is divided into two versions, namely the community version (MySQL Workbench OSS) and the commercial version (MySQL WorkbenchSE).

3.2 Software download

1. Download address

Official website: https://www.mysql.com

2. Open the official website and click DOWNLOADS

Then, click MySQL Community(GPL) Downloads

3. Click MySQL Community Server 

4. Select the appropriate version in General Availability (GA) Releases

Two installation files are provided under the Windows platform: MySQL binary distribution version (.msi installation file) and free installation version (.zip compressed file). Generally speaking, you should use the binary distribution, because this version provides a graphical installation wizard process, which is easier to use than other distributions, and you can run MySQL without starting other tools. 

  • It is recommended to download the MSI installer under the Windows system; click Go to Download Page to download

 

  • There are two installation programs for MySQL8.0 installation under Windows

mysql-installer-web-community-8.0.26.0.msi Download program size: 2.4M; installation requires networking to install components.

mysql-installer-community-8.0.26.0.msi Download program size: 450.7M; it can be installed offline during installation. recommend.

  • If you install MySQL5.7 version, select Archives, and then select the corresponding version of MySQL5.7. Download the latest version of MySQL5.7.34 here. 

 

3.3 Software installation

 After the MySQL download is complete, find the downloaded file and double-click to install it. The specific operation steps are as follows.

Step 1: Double-click the downloaded mysql-installer-community-8.0.26.0.msi file to open the installation wizard.

Step 2: Open the "Choosing a Setup Type" (select the installation type) window, in which 5 types of installation are listed, namely Developer Default (default installation type), Server only (only as a server), Client only (only as a Client), Full (full installation), Custom (custom installation). Here select the "Custom (custom installation)" type button, click the "Next (next step)" button.

Step 3: Open the "Select Products" (select products) window, you can customize the list of products that need to be installed. For example, after selecting "MySQL Server 8.0.26-X64", click the "→" Add button to choose to install the MySQL server, as shown in the figure. Using a generic approach, you can add other products that you need to install. 

At this time, if you directly "Next" (next step), the installation path of the product is the default. If you want to customize the installation directory, you can select the corresponding product, and then a hyperlink of "Advanced Options" (advanced options) will appear below.

ProgramData directory (this is a hidden directory). If you customize the installation directory, please avoid the "Chinese" directory. In addition, it is recommended that the service directory and data directory be stored separately. 

Step 4: After selecting the product to be installed in the previous step, click "Next" to enter the confirmation window, as shown in the figure. Click the Execute button to start the installation. 

Step 5: After the installation is complete, "Complete" will be displayed under the "Status" list, as shown in the figure. 

3.4 Mysql configuration

 After MySQL is installed, the server needs to be configured. The specific configuration steps are as follows.

Step 1: In the last step of the previous section, click the "Next" button to enter the product configuration window.

 

Among them, the "Config Type" option is used to set the type of the server. Click the lower triangle button to the right of the option to view 3 options, as shown in the figure.

 

  • Server Machine (server): This option represents the server, and the MySQL server can run together with other server applications, such as Web servers. The MySQL server is configured with appropriate proportions of system resources.
  • Dedicated Machine (dedicated server): This option represents a server that only runs the MySQL service. The MySQL server is configured to use all available system resources. 

Step 3: Click the "Next" button to open the window for setting the authorization method. Among them, the above option is a new authorization method provided by MySQL8.0, which adopts the SHA256-based password encryption method; the following option is the traditional authorization method (compatibility with version 5.x is reserved).

Step 4: Click the "Next" button to open the window for setting the password of the server root super administrator. As shown in the figure, you need to enter the same login password twice. You can also add other users through "Add User". When adding other users, you need to specify the user name, which host/hosts the user name is allowed to log in on, and user roles can also be specified. Users are not added here, and user management is explained in MySQL Advanced Features. 

Step 5: Click the "Next" button to open the Set Server Name window, as shown in the figure. The service name will appear in the Windows service list, and can also be used in the command line window to start and stop the service. This book sets the service name to "MySQL80". If you want to start the service automatically at startup, you can also check the "Start the MySQL Server at System Startup" option (recommended).

The following is the choice of how to run the service? You can choose one of "Standard System Account" (standard system user) or "Custom User" (custom user). The former is recommended here. 

 Step 7: Complete the configuration as shown in the figure. Click the "Finish" button to complete the configuration of the server.

 

Step 8: If there are other products that need to be configured, you can select other products and continue to configure. If not, just select "Next" (next step) and go straight through the entire installation and configuration process. 

Step 9: Finish the installation and configuration. 

If you do not configure the MySQL environment variable, you cannot directly enter the MySQL login command on the command line.

Here's how to configure MySQL environment variables:

  • Step 1: Right-click the [This PC] icon on the desktop, and select the [Properties] menu command in the pop-up shortcut menu.
  • Step 2: Open the [System] window, click the link of [Advanced System Settings].
  • Step 3: Open the [System Properties] dialog box, select the [Advanced] tab, and click the [Environment Variables] button.
  • Step 4: Open the [Environment Variables] dialog box, and select the path variable in the system variable list.
  • Step 5: Click the [Edit] button, and in the [Edit Environment Variable] dialog box, add the bin directory of the MySQL application (C:\Program Files\MySQL\MySQL Server 8.0\bin) to the variable value, using number to separate it from other paths.
  • Step 6: After the addition is complete, click the [OK] button to complete the operation of configuring the path variable, and then you can directly enter the MySQL command to log in to the database. 

3.4 Installation of MySQL5.7 version

  • Install

The installation process of this version is the same as the above process except the version number is different. Therefore, the installation screenshot of MySQL5.7.34 version is omitted here.

  • configuration

The configuration link is slightly different from the MySQL8.0 version. In most cases, you can directly select "Next", which will not affect the use of finishing. When configuring MySQL5.7 here, it is important to emphasize that the same port number cannot be used with the previously installed MySQL8.0.

4. Possible problems of installation failure

The installation and configuration of MySQL is a very simple matter, but problems may also arise during operation, especially for beginners.

Question 1: The MySQL8.0 software installation package cannot be opened or fails during the installation process. How to solve it?

Before running the MySQL8.0 software installation package, the user needs to ensure that the .Net Framework related software has been installed in the system. If this software is missing, the MySQL8.0 software cannot be installed normally.

In addition, make sure that Windows Installer is installed normally. Installing mysql8.0 on windows requires the operating system to have Microsoft Visual C++ 2015-2019 installed in advance.

 Question 2: Failed to uninstall and reinstall MySQL?

This problem is usually caused by the fact that related information is not completely cleared when MySQL is uninstalled. The solution is to delete the previous installation directory. If the service installation directory has not been specified separately in the previous installation, the default installation directory is "C:\Program Files\MySQL", delete this directory completely. At the same time, delete the MySQL Data directory. If the data directory has not been specified in the previous installation, the default installation directory is "C:\ProgramData\MySQL", which is generally a hidden directory. After deleting, reinstall it.

Question 3: How to delete the list of MySQL services that have not been uninstalled cleanly in the Windows system?

The operation method is as follows, enter "cmd" in the "search box" of the system, press the "Enter" key to confirm, and the command prompt interface will pop up. Then enter "sc delete MySQL service name" and press the "Enter" key to completely delete the remaining MySQL service.

5. MySQL login

5.1 Start and stop of service

After MySQL is installed, the server process needs to be started, otherwise the client cannot connect to the database. In the previous configuration process, MySQL has been installed as a Windows service, and MySQL is automatically started and stopped when Windows starts and stops.

Method 1: Use GUI tools

Step 1: Open windows services

  • Way 1: Computer (click the right mouse button) → Manage (click) → Services and Applications (click) → Services (click)
  • Method 2: Control Panel (click) → System and Security (click) → Administrative Tools (click) → Services (click)
  • Method 3: Task bar (click the right mouse button) → start task manager (click) → service (click)
  • Method 4: Click the [Start] menu, enter "services.msc" in the search box, and press Enter to confirm

Step 2: Find MySQL80 (click the right mouse button) → start or stop (click)

# 启动 MySQL 服务命令:
net start MySQL服务名
# 停止 MySQL 服务命令:
net stop MySQL服务名

 illustrate:

  1. The service name after start and stop should be consistent with the service name specified in the previous configuration.
  2.  If you are prompted with "denial of service" after entering the command, please open the command prompt interface as a system administrator and try again.

5.2 Login and logout of built-in client

After the MySQL service is started, you can log in to the MySQL database through the client. Note: Make sure the service is turned on.

Login method 1: MySQL built-in client

Start Menu → All Programs → MySQL → MySQL 8.0 Command Line Client

格式:
mysql -h 主机名 -P 端口号 -u 用户名 -p密码

举例:
mysql -h localhost -P 3306 -u root -pabc123 # 这里我设置的root用户的密码是abc123

 

Notice:

(1) There can be no space between -p and the password, and there can be or no space between other parameter names and parameter values. like:

mysql -hlocalhost -P3306 -uroot -pabc123

(2) It is recommended to enter the password on the next line to ensure security

mysql -h localhost -P 3306 -u root -p
Enter password:****

(3) The client and server are on the same machine, so enter localhost or the IP address 127.0.0.1. At the same time, because it is connecting to the local machine: -hlocalhost can be omitted, if the port number is not modified: -P3306 can also be omitted

Abbreviated as:

mysql -u root -p
Enter password:****

After the connection is successful, there is information about the MySQL Server service version, as well as the id of the first connection.

You can also obtain the MySQL Server service version information on the command line in the following ways:

c:\> mysql -V
c:\> mysql --version

Or after logging in, check the current version information by:

mysql> select version();

quit:

exit or quit

6. MySQL demo

6.1 Demonstration of the use of MySQL

1. View all databases

show databases;

 Why do we only see the two databases "demo" and "sys" in Workbench?

This is because Workbench is a graphical management tool, mainly for developers, and the two databases "demo" and "sys" are enough. If there are special requirements, such as monitoring various performance indicators of the MySQL database, directly operating MySQL database system files, etc., the DBA can view other system databases through SQL statements.

2. Create your own database

create database database name;

#Create atguigudb database, the name cannot be the same as the existing database.

create database atguigudb;

3. Use your own database

use database name;

#Use the atguigudb database

use atguigudb; 

Note: If the use statement is not used, and the subsequent operations on the database are not limited by the "data name", then "ERROR 1046 (3D000): No database selected" will be reported (no database selected) After using the use statement, if the connection The SQL that comes down is all for one database operation, so you don’t need to use it repeatedly. If you want to operate it for another database, you need to use it again.

4. View all tables of a library 

show tables from database name;

5. Create a new table

create table table name (

        field name data type,

        field name data type

); 

Note: If it is the last field, add a comma after it, because the function of the comma is to separate each field.

# create student table

create table student(

        id int,

        name varchar(20) #say the name can be up to 20 characters long

); 

6. View the data of a table

select * from database table name;

# View the data of the student table

select * from student;

7. Add a record

insert into table name values ​​(list of values);

#Add two records to the student table

insert into student values(1,'Zhang San');

insert into student values(2,'Li Si');

Error:

Character set problem.

8. View the creation information of the table 

show create table table name\G

#View the detailed creation information of the student table

show create table student\G

9. View the creation information of the database

show create database database name\G

#View the detailed creation information of the atguigudb database

show create database atguigudb\G

#The result is as follows

*************************** 1. row ***************************

                Database: atguigudb

Create Database: CREATE DATABASE `atguigudb` /*!40100 DEFAULT CHARACTER SET latin1 */ 1 row in set (0.00 sec)

The above results show that the atguigudb database does not support Chinese, and the default character set is latin1.

10. Delete table

drop table table name;

# delete student table

drop table student;

11. Delete the database

drop database database name;

#Delete atguigudb database

drop database atguigudb;

6.2 MySQL encoding settings

MySQL5.7

Problem reproduction: command line operation sql garbled problem

mysql> INSERT INTO t_stu VALUES(1,'Zhang San','Male');

ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'sname' at row 1

problem solved

Step 1: View encoding commands

show variables like 'character_%';

show variables like 'collation_%';

Step 2: Modify the my.ini configuration file in the mysql data directory

default-character-set=utf8 #default character set

[mysqld] # About line 76, add below it

...

character-set-server=utf8

collation-server=utf8_general_ci

 Step 3: Restart the service

Step 4: View encoding commands

show variables like 'character_%';

show variables like 'collation_%';

 

If the above configuration is correct. Then we can create a new database, create a new data table, and then add data containing Chinese.

MySQL8.0

Before MySQL 8.0, the default character set was latin1, and the utf8 character set pointed to utf8mb3. Website developers often modify the encoding to utf8 character set when designing the database. If you forget to modify the default encoding, there will be garbled characters. Starting from MySQL 8.0, the default encoding of the database is changed to utf8mb4, thus avoiding the above-mentioned garbled problem. 

7. MySQL graphical management tool

MySQL graphical management tools greatly facilitate the operation and management of the database. Commonly used graphical management tools include: MySQL Workbench, phpMyAdmin, Navicat Premium, MySQLDumper, SQLyog, dbeaver, MySQL ODBC Connector.

7.1 Tools 1. MySQL Workbench

MySQL Workbench, a graphical management tool officially provided by MySQL, fully supports versions above MySQL 5.0. MySQL Workbench is divided into community edition and commercial edition. The community edition is completely free, while the commercial edition is charged annually.

MySQL Workbench provides visual design, model building, and database management functions for database administrators, program developers, and system planners. It includes tools for creating complex data modeling ER models, forward and reverse database engineering, and can also be used to perform documentation tasks that are often time-consuming and difficult to change and manage.

Download address: http://dev.mysql.com/downloads/workbench/.

use:

First, we click the "Start" button in the lower left corner of Windows. If you are a Win10 system, you can directly see all programs. Then, find "MySQL", click on it, and find "MySQL Workbench 8.0 CE". Click to open Workbench, as shown in the following figure:

There is a local connection in the lower left corner, click it, enter the Root password, and log in to the local MySQL database server, as shown in the following figure:

 

This is a graphical interface, let me introduce you to this interface.

  • Above is the menu. The upper left is the navigation bar, where we can see the databases in the MySQL database server, including data tables, views, stored procedures, and functions; the lower left is the information bar, which can display information about the database, data tables and other objects selected above.
  • The upper middle is the work area, where you can write SQL statements, and click the third run button on the left of the upper menu bar to execute the SQL statements in the work area.
  • Below the middle is the output area, which is used to display the running status of the SQL statement, including when it started running, the running content, the running output, and the time spent. 

7.2 Tools 2. Navicat

 Navicat MySQL is a powerful MySQL database server management and development tool. It can work with any MySQL version 3.21 or above, supports triggers, stored procedures, functions, events, views, manage users, etc., and is easy to learn and use for novices. Its well-designed graphical user interface (GUI) allows users to create, organize, access and share information quickly and easily in a safe and easy way. Navicat supports Chinese and is available in a free version.

Download address: http://www.navicat.com/.

8. MySQL source code and directory

8.1 MySQL directory

8.2 MySQL source code acquisition

 First, you have to enter the MySQL download interface. Here you do not choose to use the default "Microsoft Windows", but through the drop-down bar, find "Source Code", in the operating system version below, select Windows (Architecture Independent), and then click download.

Next, unzip the downloaded compressed file, and we get the source code of MySQL.

MySQL is developed with C++. Let me briefly introduce the composition of the source code. Each subdirectory under the mysql-8.0.22 directory contains the source code of each component of MySQL:

 9. Other issues

9.1 Question 1: I forgot the root user password, how to reset it

1: Turn off mysqld (service process) through task manager or service management

2: Start mysqld through the command line + special parameters mysqld -- defaults-file="D:\ProgramFiles\mysql\MySQLServer5.7Data\my.ini" --skip-grant-tables

3: At this point, the mysqld service process has been opened. and does not require permission checks

4: mysql -uroot Log in to the server without a password. Start another client for

5: Modify the permission table

  • (1) use mysql;
  • (2)update user set authentication_string=password('新密 码') where user='root' and Host='localhost';
  • (3)flush privileges;

6: Turn off the mysqld service process through the task manager.

7: Open the mysql service through service management again.

8: You can log in with the modified new password.

9.2 Question 2: The mysql command reports "not an internal or external command"

If the mysql command is reported as "not an internal or external command", configure the bin directory of the mysql installation directory to the environment variable path. as follows:

9.3 Question 3: The character set problem of the command line client 

mysql> INSERT INTO t_stu VALUES(1,'Zhang San','Male');

ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'sname' at row 1

Reason: The server side thinks that your client's character set is utf-8, but in fact your client's character set is GBK.

View all character sets: SHOW VARIABLES LIKE 'character_set_%';  solution, set the currently connected client character set "SET NAMES GBK;"

 

 

Guess you like

Origin blog.csdn.net/m0_52096593/article/details/130895093