手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL数据库对数据库的操作

[日期:2014-01-10] 来源:Linux社区  作者:Linux [字体:大 中 小]

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>

linux
相关资讯       MySQL数据库  MySQL数据库操作 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款