登录:
- tony@ubuntu:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.1.31-1ubuntu2 (Ubuntu)Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
- tony@ubuntu:~$ mysql -uroot -p****** –default_character_set=utf8
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.31-1ubuntu2 (Ubuntu)Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
查看状态:
mysql> status
————–
mysql Ver 14.14 Distrib 5.1.31, for debian-linux-gnu (i486) using EditLine wrapper
Connection id: 37
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ”
Using delimiter: ;
Server version: 5.1.31-1ubuntu2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 1 hour 17 min 29 sec
新建数据库:
mysql> create database if not exists tst_utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.03 sec)
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| tst |
| tst_utf8 |
+——————–+
4 rows in set (0.00 sec)
选用数据库:
mysql> use tst_utf8
Database changed
新建表:
mysql> CREATE TABLE city(name VARCHAR(20), code int)
-> ;
Query OK, 0 rows affected (0.07 sec)
mysql> show tables
-> ;
+——————–+
| Tables_in_tst_utf8 |
+——————–+
| city |
+——————–+
1 row in set (0.02 sec)
增添一行数据:
mysql> INSERT INTO city
-> VALUES(’广州’,'020′);
Query OK, 1 row affected (0.07 sec)
mysql> SELECT * FROM city
-> ;
+——–+——+
| name | code |
+——–+——+
| 广州 | 20 |
+——–+——+
导入数据:
mysql> LOAD DATA LOCAL INFILE ‘/home/tony/tst.db’ INTO TABLE city;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Deleted: 0 Skipped: 0 Warnings: 0