0、停止、啟動mysql: /usr/local/mysql/bin/mysqladmin shutdown -uroot -p /usr/local/mysql/bin/mysqld_safe & -uroot -p 1、查看版本: mysql> select version(); 2、查看日志是否啟用了
mysql>show variables like 'log_bin';
如果啟用了,即ON 3、怎樣知道當(dāng)前的日志
mysql> show master status; 4、顯示數(shù)據(jù)庫 mysql> show databases; 5、顯示數(shù)據(jù)庫中的表 mysql> use mysql; mysql> show tables; 6、顯示數(shù)據(jù)表的結(jié)構(gòu): mysql> describe 表名; select * from 表名; 7、新建數(shù)據(jù)庫: mysql> create database 庫名; 8、新建表: use 庫名; create table 表名 (字段設(shè)定列表); 例如:在剛創(chuàng)建的aaa庫中建立表name,表中有id(序號,自動增長),xm(姓名),xb(性別),csny(出身年月)四個字段 use aaa; mysql> create table name (id int(3) auto_increment not null primary key, xm char(8),xb char(2),csny date); mysql> describe name; (查看表結(jié)構(gòu))
9、增加記錄 例如:增加幾條相關(guān)紀(jì)錄。 mysql> insert into name values('','張三','男','1971-10-01'); mysql> insert into name values('','白云','女','1972-05-20'); 可用select命令來驗證結(jié)果。 mysql> select * from name;
10、修改紀(jì)錄 例如:將張三的出生年月改為1971-01-10 mysql> update name set csny='1971-01-10' where xm='張三';
11、刪除紀(jì)錄 例如:刪除張三的紀(jì)錄。 mysql> delete from name where xm='張三'; 刪庫和刪表 drop database 庫名; drop table 表名; 12、查看mysql用戶: use mysql; select user(); select * from user; 13、新建用戶: 格式:grant 權(quán)限 on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by "密碼" mysql>grant select,insert,update,delete on aaa.* to user_2@localhost identified by "123456"; = grant all privileges on aaa.* to user_2@localhost identified by '123456'; mysql>grant select,insert,update,delete on *.* to user_1@"%" Identified by "123456"; grant all privileges on aaa.* to user_2@“%” identified by '123456'; 14、修改用戶權(quán)限: 新命令覆蓋就命令 15、查看用戶權(quán)限: mysql> select * from mysql.user where user='username'; mysql> show grants for username@localhost;
|