MySQL 8.0 decompressed version installation and simple sql

Windows install MySql

1. Download

Browser input https://downloads.mysql.com/archives/community/ Select the required version and install the required operating system. Here I download MySQL 8.0 and the compressed package of Windows system.

Click Download to Download. If the Download speed is very slow, you can open the Download and copy the link address to Xunlei Download.

2. Decompression installation

1. Unzip the downloaded ZIP package to the directory you want to install. Because 5.7 has been installed on my computer, I unzip it to D:\work\mysql-8.0.20

2. Add environment variables

1) Right click my computer, select properties, select advanced system settings, select environment variables under advanced, and add MYSQL_HOME, set its value to the directory D:\work\mysql-8.0.20 just extracted, click Path, select Edit, and add% MySQL at the end of the variable value_ Home% \ bin, note that the last variable should be followed by an English semicolon. Here, you can also directly add the Path of the bin directory under the MySQL decompression file at the end of the Path, that is, D:\work\mysql-8.0.20\bin.

2) Create a new my.ini file under D:\work\mysql-8.0.20. Note that the file suffix is ini

3) Edit my.ini and enter the following content in it, because my computer has installed MySQL 5.7. In order to avoid port conflict, port 3307 is selected here.

[Client]
#Set port
port = 3307
[mysqld]
#Set port
port = 3307
# Set mysql installation directory
basedir=D:\work\mysql-8.0.20\
# Set the storage directory of mysql database data
datadir=D:\work\mysql-8.0.20\data\
# Maximum connections allowed
max_connections=200
# The character set used by the server defaults to the 8-bit encoded latin1 character set
character-set-server=utf8
# The default storage engine that will be used when creating new tables
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

max_allowed_packet = 500M
[mysql]
# Set the default character set of mysql client
default-character-set=utf8

4) Right click the windows icon, select the command prompt (administrator) (A), switch the path to the bin directory of MySQL, and execute the following command to install the MySQL service. MySQL 8.0 here is the service name. If it is not entered, it defaults to MySQL.

mysqld -install mysql8.0

5) To initialize the database, enter the following command in the window just now

mysqld --initialize --user=mysql

At this time, many configuration files are produced in the D:\work\mysql-8.0.20\data directory.

6) Start the service and enter the following command in the command line window, where MySQL 8.0 is the service name set above. If it is not set, enter mysql.

net start mysql8.0

Stop service command

net stop mysql8.0

7) Connect to the database, open the data directory under MySQL, and find the file with err as the suffix

Use Notepad or Notepad + + to open, CTRL+F to search for password, find the line below, and copy the password.

Enter the following command on the command line, click enter, right-click the Enter password to paste the copied password here, and click enter to connect to the database. When the next line becomes MySQL >, the connection is successful.

mysql -u root -p

8) After MySQL > on the command line, enter the following command to modify the root password.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

9) After successfully modifying the password, enter the following command to refresh the permissions.

flush privileges;

10) Exit MySQL command line:

When you need to exit the MySQL command line, just enter exit after MySQL >; You can exit the MySQL command line.

MySQL common commands

mysql -u root -p123456		--Connect to database
show databases;				--View all databases
create database test;      	--newly build test database
use test;					--Switch database	use Database name
desc test.user;				--Displays the structure information of the specified table in the database
show tables;				--View all tables in the database
create table user (
    id int(10) not null,
    name varchar(255) not null,
    primary key(id)
);							--New data table
insert into user value ("1","Zhang San");			--Insert a piece of data
update user set name="Li Si" where id="1";		--Update a piece of data
delete from user;			--Empty table
drop table user;			--Delete table
drop database test;			--Delete database

Keywords: Windows MySQL SQL

Added by mpiaser on Wed, 15 Sep 2021 01:54:10 +0300