mysql安装: sudo apt-get install mysql-server
sudo apt-get install mysql-client
验证是否成功:sudo netstat -tap | grep mysql
change pwd: Alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new pwd';
打开服务: sudo service mysql start
使用root链接:mysql -u root -p
连接数据库use +数据库;
查看数据库: show databases;
查看表: show tables;
退出msql命令: quit/exit
新建数据库: CRATE DATABSE [NAME];
新建表:create table [name]( column_name varchar(100) not null,
column_2 int primary key)
插入数据: insert into table_name(column1,column2) values(1,2);
删除数据库: drop database name;
重命名表:rename table old_name to new_name;
alter table old_name rename new_name;
alter table old_name rename to new_name;
增加列:alter table table_name add column [name][varchar][not null];
alter table table_name add [columnname][varchar][not null];
删除列:alter table table_name drop column column_name;
重命名列: alter table table_name change old_column_name new_column_name varchar(100) not null;
改数据类型: alter table table_name modify column_name new_character
修改表中的值:update table_name set column1=value1 where ...;
删除一行记录: delete from tablename where ...;
建立索引: alter table table_name add index index_name(column_name);
create index index_name on table_name(column_name);
创建视图: create view view_name(columna, b,c ) as select 1,2,3 from table_name;
数据文件导入: load data infile '文件路径和文件名‘ into table table_name;
数据文件导出: select column1,column2 into outfile '文件路径和文件名' from table_name;
备份: mysqldump -u root databasename>newname;
mysqldump -u root databasename tablename>newname;(备份表)
恢复:source /备份文件的地址
网友评论