centos环境下创建数据库和表的方法
//查询数据库的命令:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
查询数据库中的数据表;
mysql> USE mysql;
Database changed
mysql> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
17 rows in set (0.00 sec)
数据库的创建和删除;
mysql> CREATE DATABASE beyond;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| beyond |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
删除数据库;
mysql> DROP DATABASE taotao;
Query OK, 0 rows affected (0.00 sec)
mysql> DROP TABLE user;//删除表
Query OK, 0 rows affected (0.00 sec)
创建和删除数据表;
mysql> CREATE TABLE songs (songs_name CHAR(30) NOT NULL, songs_passwd CHAR(20) NOT NULL DEFAULT '123.com',PRIMARY KEY (songs_name));
Query OK, 0 rows affected (0.02 sec)
插入新的数据记录;
mysql> INSERT INTO auth.users(user_name,user_passwd) VALUES('huangjiajv',ENCRYPT('123456'));
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO auth.users(user_name,user_passwd) VALUES('huangguanzhong',ENCRYPT('com.123'));
Query OK, 1 row affected (0.00 sec)
修改数据表信息;
mysql> UPDATE auth.users SET user_passwd=ENCRYPT('123.com') WHERE user_name='taotao';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
数据库的备份和恢复;
[root@www ~]# mysqldump -u root -p auth > mysql-auth.sql
Enter password:
[root@www ~]# ll mysql-auth.sql
-rw-r--r-- 1 root root 1863 Dec 30 01:01 mysql-auth.sql //备份数据库;
删除数据库auth;
mysql> USE mysql;
Database changed
mysql> DROP DATABASE auth;
Query OK, 1 row affected (0.01 sec)
查看一下是否删除;
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| beyond |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
[root@www ~]# mysql -u root -p auth < mysql-auth.sql
Enter password:
[root@www ~]# mysqldump -u root -p beyond > /usr/src/mysql-beyond.sql
Enter password:
[root@www ~]# ll /usr/src/mysql-beyond.sql
-rw-r--r-- 1 root root 1775 Dec 30 02:00 /usr/src/mysql-beyond.sql
[root@www ~]# mysql -u root -p beyond < /usr/src/mysql-beyond.sql
Enter password:
[root@www ~]#
备份某个数据库中的某个表;
[root@www ~]# mysqldump -u root -p mysql host user > mysql.host-user.sql
Enter password:
[root@www ~]#
详细介绍请查看全文:https://cnblogs.com/qianzf/
原文博客的链接地址:https://cnblogs.com/qzf/