MySQL

推荐书籍

《High Perormance MySQL》

 

 

安装

sudo apt-get install mysql-server

 

登陆

mysql -u user_name -p

 

数据库操作

SHOW DATABASES;

USE database_name;

CREATE database_name;

DROP database_name;

 

表操作

SHOW TABLES;

CREATE TABLE tab_name (

  id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,

  name VARCHAR(40),

  pw VARCHAR(40)  

)charset=gb2312;

DROP TABLE tab_name;

DESCRIBE tab_name;

SHOW COLUMNS FROM tab_name;

DELETE FROM tab_name;

SELECT * FROM tab_name;

 

修改表结构

ALTER TABLE tab_name ADD PRIMARY KEY(col_name)

ALTER TABLE tab_name DROP PRIMARY KEY(col_name)

ALTER TABLE tab_name ADD col_name VARCHAR(20)

ALTER TABLE tab_name MODIFY col_name VARCHAR(40) NOT NULL

ALTER TABLE tab_name RENAME TO new_tab_name

ALTER TABLE tab_name CHAGE old_col new_col VARCHAR(40)

CREATE TABLE new_tab_name LIKE old_tab_name

 

SQL脚本

当前数据库中执行 mysql < input.sql

指定数据库中执行mysql tab_name < input.sql

mysql --local-infile -u root -p   //从本地导入数据到MySQL

load data local infile '/home/...' into table tab_name fields terminated by ',' lines terminated by '\n'; //从本地导入需用绝对路径

 

MySQL优化

 

 

 

 

 

 

 

posted on 2013-10-02 16:02  int main()  阅读(166)  评论(0编辑  收藏  举报

导航