Common Management applications of MySQL Database (1)
Common Management applications of MySQL Database
1. Create a database
Create a database solin
Mysql > create database solin
Create a GBK character set called solin_gbk
Mysql > create database solin_gbk DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci
Create a UTF8 character set called solin_utf8
Mysql > create database solin_utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
2. Display the database
Command: show databases
Show the current database: select database ()
Check a library: show databases like'% solin%'
3. Delete the database
Mysql > drop database solin
4. Connect to the database
Mysql > use solin_gbk
Database changed
5. View the current database
Mysql > select database (); check that the connected database is equivalent to the pwd under linux
Mysql > select version (); view version
Mysql > select user (); View the current user, which is equivalent to the whoami under linux
6. Delete redundant accounts in the system.
Syntax: drop "user" @ "host domain name"
Mysql > select user,host from mysql.user
+-+ +
| | user | host |
+-+ +
| | root | 127.0.0.1 | |
| | root |:: 1 |
| | localhost |
| | root | localhost |
| | ysolin |
| | root | ysolin |
+-+ +
6 rows in set (0.00 sec)
Mysql > drop user'@ 'localhost'
Query OK, 0 rows affected (0.00 sec)
Mysql > select user,host from mysql.user
+-+ +
| | user | host |
+-+ +
| | root | 127.0.0.1 | |
| | root |:: 1 |
| | root | localhost |
| | ysolin |
| | root | ysolin |
+-+ +
5 rows in set (0.00 sec)
Note: if drop cannot be deleted (usually special characters or uppercase), you can delete it in the following way (for root, ysolin host as an example)
Mysql > delete from mysql.user where user='root' and host='ysolin'
Mysql > flush privileges
Business case Tips:
1. How to create a database in an enterprise?
(1) determine the character set according to the developed program
(2) specify the character set at compile time, for example:
-DDEFAUL_CHARSET=UTF8\
-DDEFAULT_COLLATION=GENERAL_CI\
Then when you build the library, you can create it by default, create database solin
(3) when compiling, there is no specified character set or a different character set from the program, how to solve it?
Specify the character set to create the database (the database should support the character set for creating the library).
Create a GBK character set called solin_gbk
Mysql > create database solin_gbk DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci
Create a UTF8 character set called solin_utf8
Mysql > create database solin_utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci