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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
| mysql> select concat('M','y','SQL'); +-----------------------+ | concat('M','y','SQL') | +-----------------------+ | MySQL | +-----------------------+ 1 row in set (0.00 sec)
mysql> select concat('M','y','SQL','5.7'); +-----------------------------+ | concat('M','y','SQL','5.7') | +-----------------------------+ | MySQL5.7 | +-----------------------------+ 1 row in set (0.00 sec)
mysql> select concat('M','y','SQL',' 5.7'); +------------------------------+ | concat('M','y','SQL',' 5.7') | +------------------------------+ | MySQL 5.7 | +------------------------------+ 1 row in set (0.00 sec)
mysql> SELECT concat_ws("-",'2012','09'); +----------------------------+ | concat_ws("-",'2012','09') | +----------------------------+ | 2012-09 | +----------------------------+ 1 row in set (0.00 sec)
mysql> SELECT concat_ws(":",'2012','09'); +----------------------------+ | concat_ws(":",'2012','09') | +----------------------------+ | 2012:09 | +----------------------------+ 1 row in set (0.00 sec)
mysql> SELECT concat_ws("-:",'2012','09'); +-----------------------------+ | concat_ws("-:",'2012','09') | +-----------------------------+ | 2012-:09 | +-----------------------------+ 1 row in set (0.00 sec)
mysql> SELECT concat_ws(":-",'2012','09'); +-----------------------------+ | concat_ws(":-",'2012','09') | +-----------------------------+ | 2012:-09 | +-----------------------------+ 1 row in set (0.00 sec)
mysql> SELECT concat_ws(null,'2012','09'); +-----------------------------+ | concat_ws(null,'2012','09') | +-----------------------------+ | NULL | +-----------------------------+ 1 row in set (0.00 sec)
mysql> select concat(1,2); +-------------+ | concat(1,2) | +-------------+ | 12 | +-------------+ 1 row in set (0.00 sec)
mysql> select strcmp('ac','ac'); +-------------------+ | strcmp('ac','ac') | +-------------------+ | 0 | +-------------------+ 1 row in set (0.06 sec)
mysql> select strcmp('ab','ac'); +-------------------+ | strcmp('ab','ac') | +-------------------+ | -1 | +-------------------+ 1 row in set (0.00 sec)
mysql> select strcmp('ac','ab'); +-------------------+ | strcmp('ac','ab') | +-------------------+ | 1 | +-------------------+ 1 row in set (0.00 sec)
mysql> help length; Name: 'LENGTH' Description: Syntax: LENGTH(str)
Returns the length of the string str, measured in bytes. A multibyte character counts as multiple bytes. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
URL: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
Examples: mysql> SELECT LENGTH('text'); -> 4
mysql> select length('1 2'); +---------------+ | length('1 2') | +---------------+ | 3 | +---------------+ 1 row in set (0.00 sec)
mysql> select length('1 2 '); +----------------+ | length('1 2 ') | +----------------+ | 4 | +----------------+ 1 row in set (0.00 sec)
mysql> select length(' 1 2 '); +-----------------+ | length(' 1 2 ') | +-----------------+ | 5 | +-----------------+ 1 row in set (0.00 sec)
mysql> help charlength;
Nothing found Please try to run 'help contents' for a list of all accessible topics
mysql> help char_length; Name: 'CHAR_LENGTH' Description: Syntax: CHAR_LENGTH(str)
Returns the length of the string str, measured in characters. A multibyte character counts as a single character. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
URL: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
mysql> select char_length(hello world); ERROR 1583 (42000): Incorrect parameters in the call to native function 'char_le ngth' mysql> select char_length('hello world'); +----------------------------+ | char_length('hello world') | +----------------------------+ | 11 | +----------------------------+ 1 row in set (0.00 sec) mysql> select upper('ADSDAsdadsf'); +----------------------+ | upper('ADSDAsdadsf') | +----------------------+ | ADSDASDADSF | +----------------------+ 1 row in set (0.02 sec)
mysql> select ucase('ADSs'); +---------------+ | ucase('ADSs') | +---------------+ | ADSS | +---------------+ 1 row in set (0.00 sec)
mysql> select lower('ADSs'); +---------------+ | lower('ADSs') | +---------------+ | adss | +---------------+ 1 row in set (0.00 sec)
mysql> select find_in_set('MySQL','a,b,c,MySQL'); +------------------------------------+ | find_in_set('MySQL','a,b,c,MySQL') | +------------------------------------+ | 4 | +------------------------------------+ 1 row in set (0.08 sec)
mysql> help field; Name: 'FIELD' Description: Syntax: FIELD(str,str1,str2,str3,...)
Returns the index (position) of str in the str1, str2, str Returns 0 if str is not found.
If all arguments to FIELD() are strings, all arguments are strings. If all arguments are numbers, they are compared a Otherwise, the arguments are compared as double.
If str is NULL, the return value is 0 because NULL fails e comparison with any value. FIELD() is the complement of EL
URL: http://dev.mysql.com/doc/refman/5.7/en/string-functio
Examples: mysql> SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo -> 2 mysql> SELECT FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo -> 0
mysql> SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo +------------------------------------------------+ | FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo') | +------------------------------------------------+ | 2 | +------------------------------------------------+ 1 row in set (0.05 sec)
mysql> select left("2013-09-28 23:58:54"); ERROR 1064 (42000): You have an error in your SQL syntax; corresponds to your MySQL server version for the right syn line 1 mysql> select left("2013-09-28 23:58:54","10"); +----------------------------------+ | left("2013-09-28 23:58:54","10") | +----------------------------------+ | 2013-09-28 | +----------------------------------+ 1 row in set (0.04 sec)
mysql> select right("2013-09-28 23:58:54","10"); +-----------------------------------+ | right("2013-09-28 23:58:54","10") | +-----------------------------------+ | 8 23:58:54 | +-----------------------------------+ 1 row in set (0.00 sec)
mysql> select right("2013-09-28 23:58:54",10); +---------------------------------+ | right("2013-09-28 23:58:54",10) | +---------------------------------+ | 8 23:58:54 | +---------------------------------+ 1 row in set (0.00 sec)
mysql> select substring("this is test string",6,2); +--------------------------------------+ | substring("this is test string",6,2) | +--------------------------------------+ | is | +--------------------------------------+ 1 row in set (0.00 sec)
mysql> select substring("this is test string",6,200); +----------------------------------------+ | substring("this is test string",6,200) | +----------------------------------------+ | is test string | +----------------------------------------+ 1 row in set (0.00 sec)
mysql> select mid("this is test string",6,200); +----------------------------------+ | mid("this is test string",6,200) | +----------------------------------+ | is test string | +----------------------------------+ 1 row in set (0.00 sec)
mysql> help mid; Name: 'MID' Description: Syntax: MID(str,pos,len)
MID(str,pos,len) is a synonym for SUBSTRING(str,pos,len).
URL: http://dev.mysql.com/doc/refman/5.7/en/string-functio
mysql> select ltrim("1 2"); +--------------+ | ltrim("1 2") | +--------------+ | 1 2 | +--------------+ 1 row in set (0.06 sec)
mysql> help trim; Name: 'TRIM' Description: Syntax: TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRI FROM] str)
Returns the string str with all remstr prefixes or suffixe none of the specifiers BOTH, LEADING, or TRAILING is given assumed. remstr is optional and, if not specified, spaces
URL: http://dev.mysql.com/doc/refman/5.7/en/string-functio
Examples: mysql> SELECT TRIM(' bar '); -> 'bar' mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx'); -> 'barxxx' mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx'); -> 'bar' mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz'); -> 'barx'
mysql> select replace('this is test string','is',"is not") +----------------------------------------------+ | replace('this is test string','is',"is not") | +----------------------------------------------+ | this not is not test string | +----------------------------------------------+ 1 row in set (0.00 sec)
mysql> select rand(); +--------------------+ | rand() | +--------------------+ | 0.4352682404548565 | +--------------------+ 1 row in set (0.06 sec)
mysql> select rand(3); +--------------------+ | rand(3) | +--------------------+ | 0.9057697559760601 | +--------------------+ 1 row in set (0.00 sec)
mysql> help rand; Name: 'RAND' Description: Syntax: RAND(), RAND(N)
Returns a random floating-point value v in the range 0 <= constant integer argument N is specified, it is used as th which produces a repeatable sequence of column values. In example, note that the sequences of values produced by RAN same both places where it occurs.
URL: http://dev.mysql.com/doc/refman/5.7/en/mathematical-f
Examples: mysql> CREATE TABLE t (i INT); Query OK, 0 rows affected (0.42 sec)
mysql> INSERT INTO t VALUES(1),(2),(3); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT i, RAND() FROM t; +------+------------------+ | i | RAND() | +------+------------------+ | 1 | 0.61914388706828 | | 2 | 0.93845168309142 | | 3 | 0.83482678498591 | +------+------------------+ 3 rows in set (0.00 sec)
mysql> SELECT i, RAND(3) FROM t; +------+------------------+ | i | RAND(3) | +------+------------------+ | 1 | 0.90576975597606 | | 2 | 0.37307905813035 | | 3 | 0.14808605345719 | +------+------------------+ 3 rows in set (0.00 sec)
mysql> SELECT i, RAND() FROM t; +------+------------------+ | i | RAND() | +------+------------------+ | 1 | 0.35877890638893 | | 2 | 0.28941420772058 | | 3 | 0.37073435016976 | +------+------------------+ 3 rows in set (0.00 sec)
mysql> SELECT i, RAND(3) FROM t; +------+------------------+ | i | RAND(3) | +------+------------------+ | 1 | 0.90576975597606 | | 2 | 0.37307905813035 | | 3 | 0.14808605345719 | +------+------------------+ 3 rows in set (0.01 sec) mysql> select ceil(5.6); +-----------+ | ceil(5.6) | +-----------+ | 6 | +-----------+ 1 row in set (0.00 sec)
mysql> select floor(5.6); +------------+ | floor(5.6) | +------------+ | 5 | +------------+ 1 row in set (0.00 sec)
mysql> select floor(5.1); +------------+ | floor(5.1) | +------------+ | 5 | +------------+ 1 row in set (0.00 sec)
mysql> select floor(5.9); +------------+ | floor(5.9) | +------------+ | 5 | +------------+ 1 row in set (0.00 sec)
mysql> select truncat(123.456,2); ERROR 1046 (3D000): No database selected mysql> select truncate(123.456,2); +---------------------+ | truncate(123.456,2) | +---------------------+ | 123.45 | +---------------------+ 1 row in set (0.00 sec)
mysql> select truncate(123.456,-2); +----------------------+ | truncate(123.456,-2) | +----------------------+ | 100 | +----------------------+ 1 row in set (0.00 sec)
mysql> select truncate(123.456,-1); +----------------------+ | truncate(123.456,-1) | +----------------------+ | 120 | +----------------------+ 1 row in set (0.00 sec)
mysql> select round(123.456); +----------------+ | round(123.456) | +----------------+ | 123 | +----------------+ 1 row in set (0.00 sec)
mysql> select round(123.456,2); +------------------+ | round(123.456,2) | +------------------+ | 123.46 | +------------------+ 1 row in set (0.00 sec)
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2018-01-09 11:12:25 | +---------------------+ 1 row in set (0.00 sec)
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2018-01-09 | +------------+ 1 row in set (0.06 sec)
mysql> select from_unixitime("123"); ERROR 1046 (3D000): No database selected mysql> select from_unixtime("123"); +----------------------------+ | from_unixtime("123") | +----------------------------+ | 1970-01-01 08:02:03.000000 | +----------------------------+ 1 row in set (0.07 sec)
mysql> select unix_timestamp(now()); +-----------------------+ | unix_timestamp(now()) | +-----------------------+ | 1515467669 | +-----------------------+ 1 row in set (0.00 sec)
mysql> select sysdate(); +---------------------+ | sysdate() | +---------------------+ | 2018-01-09 11:15:00 | +---------------------+ 1 row in set (0.00 sec)
mysql> select year(now()); +-------------+ | year(now()) | +-------------+ | 2018 | +-------------+ 1 row in set (0.00 sec)
mysql> select hour(now()); +-------------+ | hour(now()) | +-------------+ | 11 | +-------------+ 1 row in set (0.02 sec)
mysql> select to_days('20'); +---------------+ | to_days('20') | +---------------+ | NULL | +---------------+ 1 row in set, 1 warning (0.07 sec)
mysql> select to_days('2013-4-22'); +----------------------+ | to_days('2013-4-22') | +----------------------+ | 735345 | +----------------------+ 1 row in set (0.00 sec)
mysql> \h
For information about MySQL products and services, visit: http://www.mysql.com/ For developer information, including the MySQL Reference M http://dev.mysql.com/ To buy MySQL Enterprise support, training, or other produc https://shop.mysql.com/
List of all MySQL commands: Note that all text commands must be first on line and end ? (\?) Synonym for `help'. clear (\c) Clear the current input statement. connect (\r) Reconnect to the server. Optional arguments delimiter (\d) Set statement delimiter. ego (\G) Send command to mysql server, display resul exit (\q) Exit mysql. Same as quit. go (\g) Send command to mysql server. help (\h) Display this help. notee (\t) Don't write into outfile. print (\p) Print current command. prompt (\R) Change your mysql prompt. quit (\q) Quit mysql. rehash (\#) Rebuild completion hash. source (\.) Execute an SQL script file. Takes a file na status (\s) Get status information from the server. tee (\T) Set outfile [to_outfile]. Append everything use (\u) Use another database. Takes database name a charset (\C) Switch to another charset. Might be needed with multi-byte charsets. warnings (\W) Show warnings after every statement. nowarning (\w) Don't show warnings after every statement. resetconnection(\x) Clean session context.
For server side help, type 'help contents' mysql> \s -------------- mysql Ver 14.14 Distrib 5.7.17, for Win64 (x86_64)
Connection id: 20 Current database: Current user: root@localhost SSL: Not in use Using delimiter: ; Server version: 5.7.17-log MySQL Community Server (GPL) Protocol version: 10 Connection: localhost via TCP/IP Server characterset: utf8 Db characterset: utf8 Client characterset: gbk Conn. characterset: gbk TCP port: 3306 Uptime: 1 day 21 hours 34 min 49 sec
Threads: 3 Questions: 1081 Slow queries: 0 Opens: 314 Flush tables: 1 Open tables: 267 Queries per second avg: 0.006 --------------
mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)
mysql> select version; ERROR 1054 (42S22): Unknown column 'version' in 'field list' mysql> select version(); +------------+ | version() | +------------+ | 5.7.17-log | +------------+ 1 row in set (0.00 sec)
mysql> create table auto_test(id int auto_increment); ERROR 1046 (3D000): No database selected mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | company | | index_test | | mysql | | num | | performance_schema | | sakila | | sys | | table_test | | test | | world | +--------------------+ 11 rows in set (0.00 sec)
mysql> use test; Database changed mysql> create table auto_test(id int auto_increment primary key); Query OK, 0 rows affected (0.81 sec)
mysql> show create table auto_increment; ERROR 1146 (42S02): Table 'test.auto_increment' doesn't exist mysql> show create table auto_test; +-----------+------------------------------------------------------------------- -----------------------------------------------------------+ | Table | Create Table | +-----------+------------------------------------------------------------------- -----------------------------------------------------------+ | auto_test | CREATE TABLE `auto_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-----------+------------------------------------------------------------------- -----------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> insert into auto_test values(null); Query OK, 1 row affected (0.11 sec)
mysql> insert into auto_test values(null); Query OK, 1 row affected (0.05 sec)
mysql> insert into auto_test values(null); Query OK, 1 row affected (0.09 sec)
mysql> insert into auto_test values(null); Query OK, 1 row affected (0.23 sec)
mysql> select last_insert_id(); +------------------+ | last_insert_id() | +------------------+ | 4 | +------------------+ 1 row in set (0.00 sec)
mysql> select * from auto_test; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | +----+ 4 rows in set (0.00 sec)
mysql> insert into auto_test values(null); Query OK, 1 row affected (0.14 sec)
mysql> select last_insert_id(); +------------------+ | last_insert_id() | +------------------+ | 5 | +------------------+ 1 row in set (0.00 sec)
mysql> select * from auto_test; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | +----+ 5 rows in set (0.00 sec)
mysql> help ifnull; Name: 'IFNULL' Description: Syntax: IFNULL(expr1,expr2)
If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used.
URL: http://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html
Examples: mysql> SELECT IFNULL(1,0); -> 1 mysql> SELECT IFNULL(NULL,10); -> 10 mysql> SELECT IFNULL(1/0,10); -> 10 mysql> SELECT IFNULL(1/0,'yes'); -> 'yes'
mysql> SELECT IFNULL(1,0); +-------------+ | IFNULL(1,0) | +-------------+ | 1 | +-------------+ 1 row in set (0.00 sec)
mysql> password; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'passw ord' at line 1 mysql> password(); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'passw ord()' at line 1 mysql> help password();
Nothing found Please try to run 'help contents' for a list of all accessible topics
mysql> help password; Name: 'PASSWORD' Description: Syntax: PASSWORD(str)
*Note*: This function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
Returns a hashed password string calculated from the cleartext password str. The return value is a nonbinary string in the connection character set, or NULL if the argument is NULL. This function is the SQL interface to the algorithm used by the server to encrypt MySQL passwords for storage in the mysql.user grant table.
The old_passwords system variable controls the password hashing method used by the PASSWORD() function. It also influences password hashing performed by CREATE USER and GRANT statements that specify a password using an IDENTIFIED BY clause.
URL: http://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html
Examples: mysql> SET old_passwords = 0; mysql> SELECT PASSWORD('mypass'), OLD_PASSWORD('mypass'); +-------------------------------------------+------------------------+ | PASSWORD('mypass') | OLD_PASSWORD('mypass') | +-------------------------------------------+------------------------+ | *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 | 6f8c114b58f2ce9e | +-------------------------------------------+------------------------+
mysql> SET old_passwords = 1; mysql> SELECT PASSWORD('mypass'), OLD_PASSWORD('mypass'); +--------------------+------------------------+ | PASSWORD('mypass') | OLD_PASSWORD('mypass') | +--------------------+------------------------+ | 6f8c114b58f2ce9e | 6f8c114b58f2ce9e | +--------------------+------------------------+
|