MySql installation and basic usage

Source: Internet
Author: User

1. sudo apt-get install mysql-server, input administrator password, '123'

2. enter mysql promot in command line, 'mysql-u root-p', input password

3. create database "create database xoops ;"

4. allow root remote login: grant all privileges on *. * to root @ "%" identified by "passw0rd" with grant option;

5. Create a database and create a user:

1) database creation: create database test1;

2) create a user and grant permissions: grant all privileges on test1. * to user_test @ "%" identified by "passw0rd" with grant option;

3) delete a database: drop database test1;

6. delete permissions:

1) revoke all privileges on test1. * from test1 @ "% ";

2) use mysql;

3) delete from user where user = "root" and host = "% ";

4) flush privileges;

8. display all databases: show databases; display all tables in the database: show tables;

9. remotely log on to mysql: mysql-h ip-u user-p

10. backup and recovery

Back up a single database: mysqldump-uroot-p-B dbname> dbname. SQL

Back up all databases: mysqldump-uroot-p -- all-databases> all. SQL

Backup table: mysqldump-uroot-p-B dbname -- table tablename> tablename. SQL

Recover Database: mysql-uroot-p <name. SQL

Recovery table: mysql-uroot-p dbname <name. SQL (the database must be specified)

11. Sample: CREATE a DATABASE table mysql> create database if not exists my_db default charset utf8 COLLATE utf8_general_ci;

# Pay attention to the following sentence "COLLATE utf8_general_ci", which roughly means sorting by utf8 variable code format during sorting

# The default character set of all data tables created in this database will be utf8.

Mysql> create table my_table (name varchar (20) not null default '') type = myisam default charset utf8; # This statement creates a table. The default character set is utf8.

C ++ sample code:

1. boost libary is required. "sudo apt-get install libboost-date-time-dev"

2. http://dev.mysql.com/tech-resources/articles/building-mysql-connector-cpp.html

3. create database FaceDB4. create table facetable (id INT, facename TEXT, username TEXT)

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: info-contact@alibabacloud.com 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.