15.用MySQLdump备份数据库
[root@localhost ~]# mysqldump -u root -p tongcheng > 1.sql
Enter password:
[root@localhost ~]# ll
16.用mysqldump备份数据库中的某一个表
[root@localhost ~]# mysqldump -u root -p tongcheng t > 2.sql --t是表名
Enter password:
[root@localhost ~]#
17.不用登陆还原数据库
[root@localhost ~]# mysql -u root -p tongcheng <1.sql
Enter password:
[root@localhost ~]#
18.登陆后还原数据库
mysql> source 1.sql;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql>
19.修改数据库名(利用修改文件名的方法)
mysql> show variables like '%datadir%'; --查看数据库名
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> quit
Bye
[root@localhost ~]# mv /var/lib/mysql/tongcheng /var/lib/mysql/tong123 --修改数据库文件名
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| tong123 | --修改成功
+--------------------+
4 rows in set (0.00 sec)
mysql>
20.利用备份恢复修改数据库
[root@localhost ~]# mysqldump -u root -p tong123 > 12.sql --备份数据库
Enter password:
[root@localhost ~]# mysqladmin drop tong123 -u root -p --删除数据库
Enter password:
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'tong123' database [y/N] y
Database "tong123" dropped
[root@localhost ~]# mysqladmin create tongcheng -u root -p --创建一个新的数据库
Enter password:
[root@localhost ~]# mysql tongcheng -u root -p < 12.sql --还原文件
Enter password:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, 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> show databases; --查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| tongcheng |
+--------------------+
4 rows in set (0.00 sec)
mysql>
