标签:mysql
一、SQL语句
SQL语句不分大小写,但是建议使用大写
mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 5.1.73 | +-----------+ 1 row in set (0.00 sec) mysql> SELECT 4*4 #可以进行简单的运算 -> ; +-----+ | 4*4 | +-----+ | 16 | +-----+ 1 row in set (0.00 sec) mysql> SELECT DATE(); 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 ‘)‘ at line 1 mysql> SELECT -> VERSION(); +-----------+ | VERSION() | +-----------+ | 5.1.73 | +-----------+ 1 row in set (0.00 sec) mysql> SELECT CURRENT_DATE; +--------------+ | CURRENT_DATE | +--------------+ | 2015-07-30 | +--------------+ 1 row in set (0.00 sec) mysql> SELECT VERSION(),CURRENT_DATE #可以2个语句连在一起写 -> ; +-----------+--------------+ | VERSION() | CURRENT_DATE | +-----------+--------------+ | 5.1.73 | 2015-07-30 | +-----------+--------------+ 1 row in set (0.00 sec)
1 查看当前mysql有哪些数据库,创建数据库,删除数据库
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> CREATE DATABASE xxj #数据库名不能直接修改 -> ; Query OK, 1 row affected (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | xxj | +--------------------+ 4 rows in set (0.00 sec) mysql> DROP DATABASE XXJ; ERROR 1008 (HY000): Can‘t drop database ‘XXJ‘; database doesn‘t exist #数据库名是否分大小写跟你数据库所安装在的系统是否区分大小写一致,linux就区分,Windows不区分 mysql> DROP DATABASE xxj; Query OK, 0 rows affected (0.06 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec)
2 使用一个数据库
mysql> mysql> use mysql #切换当前使用的数据库 Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> use test Database changed mysql> SELECT DATABASE(); +------------+ | DATABASE() | +------------+ | test | +------------+ 1 row in set (0.00 sec) mysql> show tables; Empty set (0.00 sec) mysql> use mysqL ERROR 1049 (42000): Unknown database ‘mysqL‘ mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; #查看当前数据库下的所有表 +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | event | | func | | general_log | | help_category | | help_keyword | | help_relation | | help_topic | | host | | ndb_binlog_index | | plugin | | proc | | procs_priv | | servers | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 23 rows in set (0.00 sec) mysql> status; -------------- mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 Connection id: 9 Current database: mysql Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: ‘‘ Using delimiter: ; Server version: 5.1.73 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 1 hour 15 min 52 sec Threads: 1 Questions: 137 Slow queries: 0 Opens: 30 Flush tables: 1 Open tables: 23 Queries per second avg: 0.30 --------------
标签:mysql
原文地址:http://xiexiaojun.blog.51cto.com/2305291/1679995