PHP Mysql tutorial PHP junior and intermediate level developers must learn MySQL tutorial

The end of the article tells you how to get more free video tutorials, please pay attention

1. Download the mysql database

1. Enter MySQL official website to download

image.png

2. Click MySQL Community Server under the Community module under the DOWNLOADS module to download.

image.png


Note: According to your own computer, select the corresponding number of bits to download, this machine is 64-bit, click download. Enter the next page, this page needs to register a MySQL account, you can also download directly without registering.

2. Configure MySQL database

1. There are two types of MySQL installation files, one is in msi format and the other is in zip format. The zip format is decompressed by yourself. After decompression, MySQL can actually be used, but it needs to be configured.

If the user does not configure to use MySQL directly, the error shown in the figure will appear. This is because the environment variables are not configured.

2. Configuring environment variables is very simple: My Computer -> Properties -> Advanced -> Environment Variables

 Select PATH and add after it: The path of your mysql bin folder: D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64\bin

3. After configuring the environment variables, you also need to modify the configuration file (if there is no configuration, the error in the figure will appear when starting afterwards!: Error 2 The system cannot find the file), the default configuration of mysql-5.6.1X The file is in D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64my-default.ini, or create a my.ini file by yourself.

Modify or add configuration in it:

basedir=D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64 (the directory where mysql is located) 

datadir=D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64\data (directory where mysql is located\data)

Note: The encoding of the my.ini file must be English encoding (such as ANSI in windows), not UTF-8 or GBK, etc.

4. Run cmd as an administrator (must run as an administrator, otherwise the permissions are not enough)

Enter the command: cd D:\Program Files\JavaTool\MySQL\mysql-5.6.39-winx64\bin into the bin folder of mysql (regardless of whether environment variables have been configured, enter the bin folder, otherwise the service will still be started afterwards Error will be reported 2)

Enter mysqld -install (if you do not run as an administrator, an error will occur due to insufficient permissions: Install/Remove of the Service Denied!) 

5. The installation is successful and the service is started, enter the command: net start mysql.

6. After the service is started successfully, enter the command: mysql -u root -p (there is no password for the first login, just press Enter)!

7. Press Enter directly, login is successful.

Three, MySQL basic use tutorial (using MySQLworkbench)

1. Create a database

You can use Create Database on the toolbar to create a database directly, as shown in the figure below:

51591af706c5e8b496baafe671989992.png

Or use the command: create database database name; (note that there is a semicolon at the end) to create. Note that this method may not refresh immediately, you can right-click in the lower left corner and select Refresh all to refresh.

2. Create a table, delete a table

You can right-click on the Tables where you want to create a table, select Create Table, or use the command create table table_name(column_name column_type);

Note: Before the command to create a data table, you need to use use to specify the database you want to use. (You can right-click on the database you are going to use and select Set as Default Schema to make the database you are going to use become the default, so you don't need to write a use statement) To delete a table through the command drop table table_name;.

3. Modify the name of the table

By using the command: alter table old_name rename to new_name or rename table old_name to new_name to change the data table name.

4. Add, modify, and delete fields for the data table

Through the command alter table table_name add column_name column_type; statement to add fields to the data table.

Through the command alter table table_name change column_name new_column_name new_column_name_type; statement to modify the data table field name.

Through the command alter table table_name drop column_name; to delete the data table field.

5. About modifying the database name

In the low version of MySQL, a command rename is provided to modify the name of the database (note that it is not a database table), but this command will cause data loss, so this command has been deleted, now if you want to rename a database name If so, you need to first export all the data in the original database, then create a new database, then import the exported data into the new database, and finally delete the original database. The whole process is cumbersome, and it will be a waste of time when the amount of data is large, so it is not recommended to modify the name of the database. Therefore, when naming the database, consider giving the database a reasonable name.

4. More MYSQL video tutorials

You can follow the WeChat public account "PHP Great God" and reply "ZXMYSQL" to get it for free (Come a picture to prove it~~ Cover your face~~)

113af0b272c25f2992c5caaa4a7e9088.png

Guess you like

Origin blog.51cto.com/15115111/2675783