MySQL数据库管理常用命令

导读:MySQL数据库管理常用命令。

安装利用RPM包安装Mysql,设置TCP 3306端口的iptables

root密码管理设置root用户的密码mysqladmin -uroot password 'password'

修改root用户的密码mysqladmin -uroot -p password 'password'

数据库,表管理进入mysqlmysql -h hostname -uroot -p

创建数据库mysql> create database location

导入数据结构mysql -uroot -p location <./location.sql

查看数据库mysql> show databases

进入某个库mysql> use location

查看表信息mysql> show tables

查看表结构mysql> desc Contact

改表名mysql> rename table Contact to Contact_new

删除库mysql> drop database location

删除表mysql> drop table Contact

授权部分建立用户并授权mysql> grant all on location.* to gk1020@'10.1.11.71'identified by 'gk1020'

取消授权mysql> revoke all on location.* from gk1020@'10.1.11.71'

刷新权限mysql> flush privileges

操作语句查询mysql> select * from Contact

mysql>select count(*) from Contact

修改mysql> update Contact set RegTime=2008-01-01 000000 whereid=1

mysql>update Contact set RegTime=2008-01-01000000,CID=1 where id=1

插入mysql> insert into Contact values('','')

mysql>insert into Contact(ID,CID,Contact) values('','')

删除mysql> delete from Contact where id=1

导出导出数据库locationmysqldump -uroot -p location>./location.sql

导出某个表mysqldump -uroot -p --database location --table Contact>./contact.sql

导出数据库location的数据结构mysqldump -d -uroot -p location>./location.sql

复制表复制表ContactContact_bakmysql> create table Contact_bakas select * from Contact

复制表Contact的结构mysql> create table Contact_bak as select *from Contact where 1=2

查看正在执行的任务mysql> show processlist

说明:

location为库名,Contact为表名