Connect to the database remotely
mysql -u root -p #-u username
Write the ip address of the host you want to connect to after -h
Write the user name of the connection after -u
-p write password after carriage return
Enter the password after pressing Enter, the currently set password is toor
database operations
Create database create database database name charset=utf8;
delete database drop database database name;
switch database use database name;
View the currently selected database select database();
table operations
View all tables in the current database show tables;
create table create table table name (columns and types);
auto_increment means automatic growth
如: create table students( id int auto_increment primary key, sname varchar(10) not null );
Modify table alter table table name add|change|drop column name type; such as: alter table students add birthday datetime;
delete table drop table table name;
View table structure desc table name;
change table name rename table original table name to new table name;
View table creation statement show create table '表名';
data manipulation
Query select * from table name Increase Full column insert: insert into table name values(...) Default insert: insert into tablename(column1,...) values(value1,...) Insert multiple pieces of data at the same time: insert into table name values(...),(...)...; or insert into tablename(column1,...) values(value1,...),(value1,...)...; The primary key column is automatically increased, but it needs to occupy a place when inserting the whole column. Usually 0 is used. After the insertion is successful, the actual data shall prevail. Revise update table name set column 1=value 1,... where condition delete delete from table name where condition Tombstone, the essence is to modify the operation update alter table students add isdelete bit default 0; If you need to delete then update students isdelete=1 where ...;
Backup and restore
Enter super administrator sudo -s Enter the mysql library directory cd / var / lib / mysql Run the mysqldump command mysqldump –uroot –p database name > ~/Desktop/backup file.sql; Enter the mysql password as prompted
Data Recovery Connect to mysqk and create a database To exit the connection, execute the following command mysql -uroot -p database name < ~/Desktop/backup file.sql Enter the mysql password as prompted