1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| 1.在dos或linux下登陆命令: mysql -u root -p密码 mysql -uroot -proot 2.登陆后查看已有的数据库: show databases; 3.切换要操作的数据库: use databasename; 查看数据库中的表 show tables; desc tablename 查看已选择的数据库: select database(); 登录MySQL服务器后,查看当前时间,登录的用户以及数据库的版本 select now(),user(),version(); 新增数据库并查看: create database test_db; 查看数据库所有表和数据条数 select table_name,table_rows from tables where TABLE_SCHEMA = 'isdb' order by table_rows desc; 5.清理数据库表数据: delete from table_name; 重命名表: alter table person rename person_test; 新增主键: alter table person_test add primary key(id); 删除主键: alter table person_test drop primary key; 删除表: drop table person_test; 删除数据库: drop database test_db; 修改root密码: mysql> update mysql.user set password="root" where User="root"; mysql> flush privileges; 6.远程连接mysql数据库操作: 1).登陆要操作的数据库。 2).创建用户admin,,密码123456,赋予最高权限,命令: grant all on *.* to 'admin'@'%' identified by '123456' with grant option; 3).切换要操作的数据库: use 数据库名称; 4).查看是否以创建用户: select host,user from user; 5).本地客户端连接方式: MySql host address:58.18.174.215 Username: admin Password:123456 Port:3306
创建数据库zabbix,并且数据库编码使用utf8 create database zabbix character set utf8; 新建账户zabbix,密码zabbix insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('zabbix'));
flush privileges;
grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' with grant option; grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zabbix' with grant option; flush privileges;
show databases; use databasename; show tables; show create table demo; show columns from demo; show table STATUS; show open tables; 查看正在锁的事务 select * from information_schema.innodb_locks; 查看等待锁的事务 select * from information_schema.innodb_lock_waits;
create table tablename(field-name-1 fieldtype-1 modifiers,field-name-2 fieldtype-2 modifiers,....);
alter table tablename add new-fielname new fieldtype;
insert into tablename(fieldname-1,fieldname-2,fieldname-n)valuse(value-1,value-2,value-n);
delete from tablename where fieldname=value;
update tablename set fieldname=new-value where id=1;
select * from tablename;
desc tablename;
show create table tablename;
alter table tablename engine=InnoDB;
create table tablename(id int(11),name varchar(10) )type=INNODB;
|