标签:
root@bj-idc-testdb-001 ~]#mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.38 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. [root@bj-idc-testdb-001 ~]#mysql -u root -p123456 Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> select version(); +-----------+ | version() | +-----------+ | 5.5.38 | +-----------+ 1 row in set (0.00 sec) mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | activiti_test | | monitor | | mysql | | osa | | osa_guard | | sms | | test | | yandi_monitor | +--------------------+
mysql> create database inline default charset gbk; Query OK, 1 row affected (0.01 sec) mysql> show create database inline; +----------+----------------------------------------------------------------+ | Database | Create Database | +----------+----------------------------------------------------------------+ | inline | CREATE DATABASE `inline` /*!40100 DEFAULT CHARACTER SET gbk */ | +----------+----------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> grant all on inline.* to inline@localhost identified by ‘inline‘; Query OK, 0 rows affected (0.00 sec)
mysql> show grants for inline@localhost; +---------------------------------------------------------------------------------------------------------------+ | Grants for inline@localhost | +---------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO ‘inline‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*49129FD3218473FFCCE66D799E25FB6AFD6E0A73‘ | | GRANT ALL PRIVILEGES ON `inline`.* TO ‘inline‘@‘localhost‘ | +---------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
mysql> use inline Database changed
mysql> create table test(
-> id int,
-> name varchar(16))
-> engine innodb default charset gbk;
Query OK, 0 rows affected (0.01 sec)
mysql> show create table test;
+-------+--------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`name` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-------+--------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show variables like ‘char%‘;
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> desc test
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec) mysql> insert into test value(0,‘inlineuser‘); Query OK, 1 row affected (0.00 sec)
mysql> insert into test value(1,‘inlineuser‘),(2,‘中文‘); Query OK, 2 rows affected (0.02 sec) Records: 2 Duplicates: 0 Warnings: 0
mysql> ?select * from test; +------+------------+ | id | name | +------+------------+ | 0 | inlineuser | | 1 | inlineuser | | 2 | 中文 | +------+------------+ 3 rows in set (0.00 sec)
mysql> select * from test where id>1; +------+--------+ | id | name | +------+--------+ | 2 | 中文 | +------+--------+ 1 row in set (0.00 sec)
ysql> update test set name=‘inuser‘ where id=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from test; +------+--------------+ | id | name | +------+--------------+ | 0 | inlineuser | | 1 | inuser | | 2 | 中文 | +------+--------------+ 3 rows in set (0.00 sec)
mysql> alter table test add age int(4) after id; Query OK, 3 rows affected (0.01 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> desc test; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | age | int(4) | YES | | NULL | | | name | varchar(16) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql>
[root@bj-idc-testdb-001 ~]#mysqldump -B inline,mysql >/tmp/backup.sqlmysqldump: Got error: 1049: Unknown database ‘inline,mysql‘ when selecting the database [root@bj-idc-testdb-001 ~]#mysqldump -B inline mysql >/tmp/backup.sql -- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly. [root@bj-idc-testdb-001 ~]#mysqldump --events -B inline mysql >/tmp/backup.sql
mysql> delete from test; Query OK, 3 rows affected (0.02 sec)
[root@bj-idc-testdb-001 ~]#vim /tmp/backup.sql
[root@bj-idc-testdb-001 ~]#mysql </tmp/backup.sql
[root@bj-idc-testdb-001 ~]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.38 MySQL Community Server (GPL) by Remi
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> use inline
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> select * from test;
+------+------+--------------+
| id | age | name |
+------+------+--------------+
| 0 | NULL | inlineuser |
| 1 | NULL | inlineunuser |
| 2 | NULL | 中文 |
+------+------+--------------+
3 rows in set (0.00 sec)
mysql> desc test
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| age | int(4) | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec) [root@bj-idc-testdb-001 ~]#sed -i "s/gbk/utf8/g" /tmp/backup.sql [root@bj-idc-testdb-001 ~]#vim /tmp/backup.sql [root@bj-idc-testdb-001 ~]#mysql < /tmp/backup.sql [root@bj-idc-testdb-001 ~]#mysql inline Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.5.38 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> select * from test; +------+------+--------------+ | id | age | name | +------+------+--------------+ | 0 | NULL | inlineuser | | 1 | NULL | inlineunuser | | 2 | NULL | 中文 | +------+------+--------------+ 3 rows in set (0.00 sec) mysql>
[root@bj-idc-testdb-001 ~]#/usr/bin/mysqld_safe --skip-grant-tables & mysql> select host,user,password from mysql.user where user=‘root‘; +-----------------------+------+-------------------------------------------+ | host | user | password | +-----------------------+------+-------------------------------------------+ | localhost | root | *509910ED20429303306B7D5FA9215C7EC9E54B68 | | localhost.localdomain | root | | | 127.0.0.1 | root | | +-----------------------+------+-------------------------------------------+ 3 rows in set (0.00 sec) mysql> update mysql.user set password=password(123456) where user=‘root‘ and host=‘localhost‘; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> exit Bye [root@bj-idc-testdb-001 ~]#/etc/init.d/mysqld stop 150920 09:37:22 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended Stopping mysqld: [ OK ] [1]+ Done /usr/bin/mysqld_safe --skip-grant-tables [root@bj-idc-testdb-001 ~]#/etc/init.d/mysqld start Starting mysqld: [ OK ] [root@bj-idc-testdb-001 ~]#mysql -uroot -p123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.38 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql>
mysql> alter table test add primary key idx_p(id);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> desc test
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| age | int(4) | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table test add index idx_name(name);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table test add mobile char(11);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> desc test
-> ;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| age | int(4) | YES | | NULL | |
| name | varchar(16) | YES | MUL | NULL | |
| mobile | char(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from test;
+----+------+--------------+--------+
| id | age | name | mobile |
+----+------+--------------+--------+
| 0 | NULL | inlineuser | NULL |
| 1 | NULL | inlineunuser | NULL |
| 2 | NULL | 中文 | NULL |
+----+------+--------------+--------+
3 rows in set (0.00 sec)
mysql> insert into test values(3,5,‘foson‘,‘13455556666‘),(4,5,‘foson‘,‘13577889966‘);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from test;
+----+------+--------------+-------------+
| id | age | name | mobile |
+----+------+--------------+-------------+
| 0 | NULL | inlineuser | NULL |
| 1 | NULL | inlineuser | NULL |
| 2 | NULL | 中文 | NULL |
| 3 | 5 | foson | 13455556666 |
| 4 | 5 | foson | 13577889966 |
+----+------+--------------+-------------+
5 rows in set (0.00 sec) mysql> alter table test add index idx_m (mobile(8));
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show index from test;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| test | 0 | PRIMARY | 1 | id | A | 5 | NULL | NULL | | BTREE | | |
| test | 1 | idx_name | 1 | name | A | 5 | NULL | NULL | YES | BTREE | | |
| test | 1 | idx_m | 1 | mobile | A | 5 | 8 | NULL | YES | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)
mysql> show index from test\G;
*************************** 1. row ***************************
Table: test
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: test
Non_unique: 1
Key_name: idx_name
Seq_in_index: 1
Column_name: name
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: test
Non_unique: 1
Key_name: idx_m
Seq_in_index: 1
Column_name: mobile
Collation: A
Cardinality: 5
Sub_part: 8
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
3 rows in set (0.00 sec)
ERROR:
No query specified mysql> alter table test drop index idx_name;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table test drop index idx_m;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show index from test\G;
*************************** 1. row ***************************
Table: test
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
1 row in set (0.00 sec)
ERROR:
No query specified mysql> alter table test add index idx_n_m (name(6),mobile(8));
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show index from test\G;
*************************** 1. row ***************************
Table: test
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: test
Non_unique: 1
Key_name: idx_n_m
Seq_in_index: 1
Column_name: name
Collation: A
Cardinality: 5
Sub_part: 6
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: test
Non_unique: 1
Key_name: idx_n_m
Seq_in_index: 2
Column_name: mobile
Collation: A
Cardinality: 5
Sub_part: 8
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
3 rows in set (0.00 sec)
ERROR:
No query specified mysql> select * from test where name=‘foson‘ and mobile like ‘135%‘; +----+------+---------+-------------+ | id | age | name | mobile | +----+------+---------+-------------+ | 4 | 5 | foson | 13577889966 | +----+------+---------+-------------+ 1 row in set (0.00 sec) mysql> explain select * from test where name=‘foson‘ and mobile like ‘135%‘; +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | 1 | SIMPLE | test | range | idx_n_m | idx_n_m | 46 | NULL | 1 | Using where | +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ 1 row in set (0.01 sec) mysql> alter table test drop index idx_n_m; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> explain select * from test where name=‘foson‘ and mobile like ‘135%‘; +----+-------------+-------+------+---------------+------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+-------------+ | 1 | SIMPLE | test | ALL | NULL | NULL | NULL | NULL | 5 | Using where | +----+-------------+-------+------+---------------+------+---------+------+------+-------------+ 1 row in set (0.00 sec) mysql> mysql> alter table test add index idx_n_m (name(6),mobile(8)); Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> explain select * from test where mobile like ‘135%‘; +----+-------------+-------+------+---------------+------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+-------------+ | 1 | SIMPLE | test | ALL | NULL | NULL | NULL | NULL | 5 | Using where | +----+-------------+-------+------+---------------+------+---------+------+------+-------------+ 1 row in set (0.00 sec) mysql> explain select * from test where name=‘foson‘ and mobile like ‘135%‘; +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | 1 | SIMPLE | test | range | idx_n_m | idx_n_m | 46 | NULL | 1 | Using where | +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ 1 row in set (0.00 sec) mysql> explain select * from test where name=‘foson‘; +----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+ | 1 | SIMPLE | test | ref | idx_n_m | idx_n_m | 21 | const | 2 | Using where | +----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+ 1 row in set (0.00 sec) mysql>
标签:
原文地址:http://my.oschina.net/zhailibao2010/blog/508934