Mysql connects to the database, mysql connects to the database
Wow, there's something that comes in touch with the background today! Isn't "mysql" counted? Hey, I feel very happy to write code. Let's summarize it today! (Good god, don't like it, don't spray it)
1. Start mysql and link the data! Yes, right?
Mysql-uroot-p // connect data
Net start mysql // start mysql
2. query the data on the current server.
Show databases;
3,Create a database
Create database jddb ------- database Name (jddb)
4. Use a database
Use jddb;
5. query the tables in the current database
Show tables;
6. Insert a table to the database
create table user(id int auto_increment primary key,userName varchar(20) not null,pwd varchar(30) not null,age int not null,sex varchar(4) not null);
7. insert data into the table
Insert into user (userName, pwd, age, sex) values ('xiaa', 'abc123', 21, 'male ');
Insert into user (userName, pwd, age, sex) values ('xiaof ', 'ccccc', 48, 'femal ');
Insert into user (userName, pwd, age, sex) values ('xiaog', 'ccccc ', 91, 'male ');
8. query data
Select * from user;
Note: (this may cause some small garbled events, so solve this problem!
// Solve the garbled problem. Write character-set-server = gbk in my. ini [mysqld] to restart
Server
)
9. The data in the inserted table can be modified.
Update user set age = 20 where userName = 'xiaa ';
10,Query
Select userName, age, sex from user;
Select * from user where sex = 'male'
11,Delete
Delete from user where age> 90 (the third data entry will be deleted)
12,Modify Table Name
Alter table user rename to huiyuan
13,Delete table
-- Drop table user; (delete the previously inserted table)
-- Drop database jddb; (delete database)
14. Back up the database in the future!
// Export Database Backup Data
Mysqldump-uroot-p> g: \ jddb. SQL
// Import database restoration data
Source g: \ jddb. SQL
Mysql-uroot-p jddb <g: \ jddb. SQL
15. Shut down the database
Net stopt mysql // start mysql