下面是我们经常会用到且非常有用的MySQL命令。下面你看到#表示在Unix命令行下执行命令,看到mysql>表示当前已经登录MySQL服务器,是在mysql客户端执行mysql命令。
登录MySQL,如果连接远程数据库,需要用-h指定hostname。
登录MySQL,如果连接远程数据库,需要用-h指定hostname。
# [mysql dir]/bin/mysql -h hostname -u root -p
创建一个数据库。
mysql> create database [databasename];
列出所有数据库。
mysql> show databases;
切换到一个数据库。
mysql> use [db name];
显示一个数据库的所有表。
mysql> show tables;
查看数据表的字段格式。
mysql> describe [table name];
删除一个数据库。
mysql> drop database [database name];
删除一个数据表。
mysql> drop table [table name];
显示一个数据表的所有数据。
mysql> SELECT * FROM [table name];
返回指定数据表的各列信息。
mysql> show columns from [table name];
使用值“whatever”过滤显示选定的某些行。
mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";
显示所有包含name为”Bob”和phone number为“3444444”的记录。
mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';
显示所有不包含name为”Bob”和phone number为“3444444”的记录,并以phone_number字段排序。
mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;
显示所有的name以字母“bob”开头和phone number为“3444444”的记录。
mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';
显示name以字母“bob”开头和phone number为“3444444”的第1至第5条记录。
mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;
使用正则表达式查找记录。使用“正则表达式二进制”强制区分大小写。此命令查找以a开头的任何记录。
mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";
返回唯一不同的记录。
mysql> SELECT DISTINCT [column name] FROM [table name];
以升序或降序显示选定的记录。
mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
返回行数。
mysql> SELECT COUNT(*) FROM [table name];
统计指定列值的总和。
mysql> SELECT SUM(*) FROM [table name];
联结表。
mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;
新建一个用户。以root登录。切换到mysql数据库,创建用户,刷新权限。
# mysql -u root -p mysql> use mysql; mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password')); mysql> flush privileges;
从unix命令行更改用户密码。
# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'
# /etc/init.d/mysql stop # mysqld_safe --skip-grant-tables & # mysql -u root
mysql> use mysql; mysql> update user set password=PASSWORD("newrootpassword") where User='root'; mysql> flush privileges; mysql> quit
# /etc/init.d/mysql stop # /etc/init.d/mysql start
# mysqladmin -u root password newpassword
# mysqladmin -u root -p oldpassword newpassword
# mysql -u root -p
mysql> use mysql; mysql> grant usage on *.* to bob@localhost identified by 'passwd'; mysql> flush privileges;
mysqldump -h database_ip -u Username --password=123456 --opt databasename > backup-file.sql mysqldump -h database_ip -d -u Username --password=123456 databasename >database_structure.sql
# mysql -u root -p
mysql> use mysql; mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N'); mysql> flush privileges;
mysql> grant all privileges on databasename.* to username@localhost; mysql> flush privileges;
mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
mysql> DELETE from [table name] where [field name] = 'whatever';
mysql> flush privileges;
mysql> alter table [table name] drop column [column name];
mysql> alter table [table name] add column [new column name] varchar (20);
mysql> alter table [table name] change [old column name] [new column name] varchar (50);
mysql> alter table [table name] add unique ([column name]);
mysql> alter table [table name] modify [column name] VARCHAR(3);
mysql> alter table [table name] drop index [colmn name];
mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);
# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
# [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql
# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql
# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql
mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));
mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');
select title from book into outfile '/tmp/outfile.txt';
select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1);
select * from phome_ecms_wma where title in (select distinct title from phome_ecms_wma);
select *,count(distinct title) INTO OUTFILE '/tmp/table.bak' from phome_ecms_wma group by title; delete from phome_ecms_wma; LOAD DATA INFILE '/tmp/table.bak' REPLACE INTO TABLE phome_ecms_wma character set utf8;
SELECT *FROM url ORDER BY RAND() LIMIT 5;
mysql> show variables like "character_set%";
mysql> alter table table_name change last_action last_action datetime NOT NULL default '0000-00-00 00:00:00';
mysql> ALTER TABLE host ADD ks_mac VARCHAR(100);
mysql> ALTER TABLE table_name DROP field_name;
mysql>alter table t1 rename t2;
mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]); mysql> alter table tablename add index emp_name (name);
mysql> alter table tablename add primary key(id);
mysql> alter table tablename add unique emp_name2(cardnumber);
mysql>alter table tablename drop index emp_name;
mysql> GRANT ALL PRIVILEGES ON database_test.* to root@192.168.1.9 IDENTIFIED BY '123456'; mysql> FLUSH PRIVILEGES;
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]