MySQL (1) Installation and Getting Started
System information: windows 10, mysql-8.0.19-winx64 is
released for communication and future review.
Ready to work
download
mysql-8.0.19-winx64 download link , zip file one-click download
installation
unzip
Unzip the downloaded compressed file to the target directory (the final MySQL installation directory), for example
D:\software\MySQL\mysql-8.0.19-winx64
Configure environment variables
Control Panel>All Control Panel Items>System—Advanced System Settings—Environment Variables
Variable name: MYSQL_HOME
Variable value: D:\software\MySQL\mysql-8.0.19-winx64
Generate data file
Run cmd as administrator
d:
cd D:\software\MySQL\mysql-8.0.19-winx64\bin
mysqld --initialize-insecure --user=mysql
Execute the above command to generate the data directory in the D:\software\MySQL\mysql-8.0.19-winx64 directory
Install and start MySQL
Excuting an order:
mysqld -install
net start MySQL
Pay attention to the order, otherwise an error will be reported: the service name is invalid.
Log in to MySQL
Connect to the local MySQL. There is no password for the first login. You don't need to enter a password, just press Enter.
mysql -u root -p
Possible problems
报错:Can’t connect to MySQL server on ‘localhost’ (10061)
Reason: MySQL service is not enabled on the computer
solve:
- Windows+R invokes the running window, enters
services.msc
enter, and the service (local) interface pops up - Find the MySQL service in the service list on the right (if not, please execute
mysqld -install
) - Turn on the service
change Password
ALTER USER'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'****', take changing the password as ysli123
an example
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ysli123';
flush privileges;
flush privileges
Save the modified content, remember to enter the password when you enter again after modification
drop out
quit
operating
Database operation
Sample database name: mysql_ysli
Create database
create database <database name>;
create database mysql_ysli;
Delete database
drop database <database name>;
drop database mysql_ysli;
Select database
use <database name>;
use mysql_ysli;
Data table operation
Sample data table name: ysli_table
Create data table
The following information is required to create a MySQL data table:
- Table Name
- Table field name
- Define each table field
CREATE TABLE table_name (column_name column_type);
create table ysli_table(
ysli_id int not null auto_increment,
ysli_title varchar(100) not null,
ysli_body varchar(100) not null,
primary key (ysli_id)
)engine=InnoDB default charset=utf8;
- The auto_increment definition column is an attribute of self-increment, which is generally used for the primary key, and the value is automatically increased by 1.
- The primary key keyword is used to define the column as the primary key. You can use multiple columns to define the primary key, separated by commas.
- engine sets the storage engine, charset sets the encoding.
- If you don't want the field to be null, you can set the field's property to not null, and an error will be reported if the data entered in the field is null when operating the database.
Delete data table
drop database <data table name>;
drop table ysli_table;
Insert data
insert into <table_name> ( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
Example (character data needs to use single or double quotes):
insert into ysli_table (ysli_title,ysli_body)
values
('example','123mysql内容');
Query data table
SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[LIMIT N][ OFFSET M]
- You can use one or more tables in the query statement, separate the tables with a comma (,), and use the WHERE statement to set the query conditions.
- The SELECT command can read one or more records.
- You can use an asterisk (*) to replace other fields, the SELECT statement will return all the field data of the table
- You can use the WHERE statement to include any conditions.
- You can use the LIMIT property to set the number of records returned.
- You can use OFFSET to specify the data offset at which the SELECT statement starts to query. By default, the offset is 0.
select * from ysli_table;
Main reference: rookie tutorial