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. 允許root遠程登陸: 從所有主機:grant all privileges on *.* to root@"%" identified by "passw0rd" with grant option;
5. 建數據庫,創建user:
1) 建庫:create database test1;
2) 建用戶,賦權:grant all privileges on test1.* to user_test@"%" identified by "passw0rd" with grant option;
3) 刪除數據庫:drop database test1;
6. 刪除權限:
1) revoke all privileges on test1.* from test1@"%";
2) use mysql;
3) delete from user where user="root" and host="%";
4) flush privileges;
8. 顯示所有的數據庫:show databases; 顯示庫中所有的表:show tables;
9. 遠程登錄mysql:mysql -h ip -u user -p
10. 備份和恢復
備份單個數據庫:mysqldump -uroot -p -B dbname > dbname.sql
備份全部數據庫:mysqldump -uroot -p --all-databases > all.sql
備份表: mysqldump -uroot -p -B dbname --table tablename > tablename.sql
恢復數據庫:mysql -uroot -p < name.sql
恢復表:mysql -uroot -p dbname < name.sql (必須指定數據庫)
11. Sample:創建數據庫表 mysql>CREATE DATABASE IF NOT EXISTS my_db default charset utf8 COLLATE utf8_general_ci;
#注意後面這句話 "COLLATE utf8_general_ci",大致意思是在排序時根據utf8變碼格式來排序
#那麼在這個數據庫下創建的所有數據表的默認字符集都會是utf8了
mysql>create table my_table (name varchar(20) not null default '')type=myisam default charset utf8; #這句話就是創建一個表了,制定默認字符集為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)