mysql-sql语言参考
字段去重查询
select distinct style from music
批量修改某字段
update music set style = “ost” where style like “%影视剧%”
先查询,再添加或修改数据字段
select * from music where language is null
update music set language = “外国” where language is null
mysql的sql实现
mysql> alter table 国产 rename to guochan;<br/> 习惯上函数用大写,但小写也可以<br/> mysql> select now();<br/> select ascii('f');<br/> 返回字符串str的第一个字符的ASCII值(str是空串时返回0),总是加单引号。<br/> select CHAR(77,121,83,86,77);
增删改查语句 MariaDB [EMP]> insert into Employees values (100,18,'aa','bb');<br/> Query OK, 1 row affected (0.02 sec) MariaDB [EMP]> insert into Employees values (101,19,'a2','b2');<br/> Query OK, 1 row affected (0.02 sec) MariaDB [EMP]> insert into Employees values (101,19,'zara','b3');<br/> Query OK, 1 row affected (0.01 sec) MariaDB [EMP]> insert into Employees values (105,30,'a4','b4');<br/> Query OK, 1 row affected (0.01 sec) MariaDB [EMP]> select * from Employees;<br/> +-----+-----+-------+------+<br/> | id | age | first | last |<br/> +-----+-----+-------+------+<br/> | 100 | 18 | aa | bb |<br/> | 101 | 19 | a2 | b2 |<br/> | 101 | 19 | zara | b3 |<br/> | 105 | 30 | a4 | b4 |<br/> +-----+-----+-------+------+<br/> 4 rows in set (0.00 sec) MariaDB [EMP]> UPDATE Employees SET id=102 WHERE first='zara';<br/> Query OK, 1 row affected (0.01 sec)<br/> Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [EMP]> select * from Employees;<br/> +-----+-----+-------+------+<br/> | id | age | first | last |<br/> +-----+-----+-------+------+<br/> | 100 | 18 | aa | bb |<br/> | 101 | 19 | a2 | b2 |<br/> | 102 | 19 | zara | b3 |<br/> | 105 | 30 | a4 | b4 |<br/> +-----+-----+-------+------+<br/> 4 rows in set (0.00 sec) MariaDB [EMP]> delete from Employees where id=105;<br/> MariaDB [EMP]> select * from Employees;<br/> +-----+-----+-------+------+<br/> | id | age | first | last |<br/> +-----+-----+-------+------+<br/> | 100 | 18 | aa | bb |<br/> | 101 | 19 | a2 | b2 |<br/> | 102 | 19 | zara | b3 |<br/> +-----+-----+-------+------+<br/> 3 rows in set (0.00 sec) MariaDB [EMP]> insert into Employees values(108,29,'wu','ma');<br/> Query OK, 1 row affected (0.03 sec) MariaDB [EMP]> insert into Employees values(109,26,'wang','wei');<br/> Query OK, 1 row affected (0.02 sec) MariaDB [EMP]> select * from Employees;<br/> +-----+-----+-------+------+<br/> | id | age | first | last |<br/> +-----+-----+-------+------+<br/> | 100 | 18 | aa | bb |<br/> | 101 | 19 | a2 | b2 |<br/> | 102 | 19 | zara | b3 |<br/> | 108 | 29 | wu | ma |<br/> | 109 | 26 | wang | wei |<br/> +-----+-----+-------+------+<br/> 5 rows in set (0.00 sec) show variables like '%FOREIGN%';<br/>SET FOREIGN_KEY_CHECKS=0; delete from geographical_position where type = 1<br/>select distinct type from geographical_position mysql> create user 'ab'@'localhost' identified by 'weeee';<br/>mysql> select user,host,password from mysql.user; INSERT(str,pos,len,newstr)<br/>instr mysql> select instr('contents','t');<br/>+-----------------------+<br/>| instr('contents','t') |<br/>+-----------------------+<br/>| 4 |<br/>+-----------------------+<br/>1 row in set (0.00 sec) mysqldump -u root -d -R --add-drop-table spa >spa.sql<br/>sed -i '1i\use spa;' spa.sql<br/>sed -i '1i\create database spa;' spa.sql<br/>sed -i '1i\drop database if exists spa;' spa.sql<br/>mysqldump -u root --add-drop-table spa action_buttons>>spa.sql<br/>mysqldump -u root --add-drop-table spa menu>>spa.sql<br/>mysqldump -u root --add-drop-table --extended-insert=false spa tb_sequence>>spa.sql<br/>mysqldump -u root --add-drop-table spa role --where="id=20" >>spa.sql<br/>mysqldump -u root --add-drop-table spa role_button_relation --where="role_id=20" >>spa.sql<br/>mysqldump -u root --add-drop-table spa user_role_relation --where="role_id=20" >>spa.sql<br/>mysqldump -u root --add-drop-table spa system_user --where="username='admin'" >>spa.sql -d, --no-data No row information.<br/>-R, --routines Dump stored routines (functions and procedures). select * from tb_sequence limit 0,1<br/>limit是mysql的语法<br/>select * from table limit m,n<br/>其中m是指记录开始的index,从0开始,表示第一条记录<br/>n是指从第m+1条开始,取n条。<br/>select * from tablename limit 2,4<br/>即取出第3条至第6条,4条记录 [root@db mysql]# mysqlshow<br/>[root@db mysql]# mysql -e 'select user,password,host from mysql.user'<br/>mysql> delete from user where user = ''; 删除匿名用户<br/>mysql> drop user ''@localhost ;
转发申明:
本文转自互联网,由小站整理并发布,在于分享相关技术和知识。版权归原作者所有,如有侵权,请联系本站 top8488@163.com,将在24小时内删除。谢谢