Learn PHP will have to mention MySQL, although there are phpmyadmin such tools can be graphical operation of the database, but I still want to learn PHP to use the command line to manipulate the database. Here's a summary of my studies, including command line connection databases, viewing current users, viewing current storage engines, and viewing MySQL versions of BASIC commands.
Connecting to a database
Command format:mysql-h hostname-u username-p
-h Specifies the host of the MySQL database to which you want to connect, and if this is the local computer, you can omit it.
-u Specifies the user name of the login, or, if not specified, the operating system's login username by default.
-p Specifies a password. You can enter the password directly after-p, but this way the password will be displayed. A good way is not to enter the password, enter the system will prompt for a password, and then enter the password will be used * display. This is relatively safe. The welcome interface appears when the connection is correct. As shown in the following illustration:
Exit the database using the QUIT command.
When an application connects to a database, it is recommended that you do not use the root administrator user connection. A good approach is to manipulate the database for ordinary users who create one or several specific permissions for the application. For ordinary users to follow the principle of least privilege, this can maximize the security of the database.
Various database Information view commands
- View the version of the database Select Edition ();
- View the storage engine supported by the database and the current default storage engine show engines;
As shown in the following illustration, all the storage engines for the MySQL database are displayed, default is the current defaults storage engine, and whether to support transactions such as: Write a picture description here
- View the user name of the currently logged-on database, select User ();
- View permissions for the currently logged-on database user show grants for Sally; –sally for User name
- View all databases that the current user can see show databases;
- Go to the specified database use books; –books for Database name
- View all tables in the current database show table;
- View the structure information of a table describe customers; –customers for Table name
The above command runs as shown in the following illustration:
The above is the summary of MySQL connection and basic Information view command, I hope you like.