Mysql connects to the database, mysql connects to the database

Source: Internet
Author: User
Tags import database

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


9. The data in the inserted table can be modified.

Update user set age = 20 where userName = 'xiaa ';


Select userName, age, sex from user;

Select * from user where sex = 'male'


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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.