Home Database Mysql Tutorial A detailed introduction to the method of creating a MySQL database using commands

A detailed introduction to the method of creating a MySQL database using commands

Mar 21, 2017 pm 01:39 PM

The following editor will bring you an article on how to create a MySQL database(de1) using commands. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

1. Connect to MYSQL

Format: mysql -h host address -u username -p user Password

1. Connect to MYSQL on this machine.

First open the DOS window, then enter the directory mysql\bin, and then type the command mysql -u root -p. After pressing Enter, you will be prompted to enter your password. Note that the user name can be preceded by

There can be no spaces, but there must be no spaces before the password, otherwise you will be asked to re-enter the password.

If you have just installed MYSQL, the super user root does not have a password, so just press Enter You can now enter MYSQL. The MYSQL prompt is:
mysql>

2. Connect to MYSQL on the remote host. Assume that the IP of the remote host is: 110.110.110.110, the user name is root, and the password is abcd123.

Then type the following command:

mysql -h110.110.110.110 -u root -p 123; (Note: There is no need to add a space between u and root, and the same is true for others )

3. Exit the MYSQL command: exit (Enter)

## 2. Change the password

Format: mysqladmin -u username -p old password password new password. For example

1. Add a password ab12 to root. First, enter the directory mysql\bin under DOS, and then type the following command

mysqladmin -u root -password ab12

2. Then change the root password to djg345.

mysqladmin -u root -p ab12 password ******

##3. Create database1. CREATE DATABASE database name;

2. GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON database name.* TO database name

@localhost IDENTIFIED BY 'Password';


3, SET PASSWORD FOR

'Database name'@'localhost' = OLD_PASSWORD('Password');

Execute 3 commands in sequence to complete Database creation. Note: Chinese "Password" and "Database" need to be set by the user himself.

———————————————————————————————————— —

Now introduce some commonly used MYSQL commandsNote: You must first log in to MYSQL. The following operations are all prompted by MYSQL symbol, and each command ends with a semicolon.

1. Operation skills#1. If you find that you forgot to add a semicolon after pressing Enter when typing a command, you do not need to type it again. command, just hit a semicolon and press Enter.

That is to say, you can divide a complete command into several lines and type it with a semicolon as the end mark.

2. You can use the cursor up and down keys to call up previous commands.

2. Commonly used commands

1. Display the database list in the current database server:

mysql> SHOW DATABASES;

2. Create database:

mysql> CREATE DATABASE library name;

3. Create data table :

mysql> USE library name;

mysql> CREATE TABLE table name (field name VARCHAR(20), field name CHAR(1));

4. Delete database:

mysql> DROP DATABASE library name;

5. Delete data table:

mysql> DROP TABLE table name;

6. Clear the records in the table:

mysql> DELETE FROM table name;

7. Go to Insert records into the table:

mysql> INSERT INTO table name VALUES ("hyq", "M");

8. Update data in the table:

mysql-> UPDATE table name SET field name 1='a', field name 2='b' WHERE field name 3='c';

9. Use Load data into the data table in text mode:

mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE table name;

10. Import .sql file command:

mysql> USE database name;

mysql> SOURCE d:/mysql.sql;

11. Command line modification root password:

mysql> UPDATE mysql.user SET password=PASSWORD('new password') WHERE User='root';

mysql> FLUSH PRIVILEGES;

3. An instance of creating a database, creating a table, and inserting data using the

drop database if exists school; //如果存在sudu则删除
create database sudu; //建立库sudu
use school; //打开库sudu
create table teacher //建立表TEACHER
(
id int(3) auto_increment not null primary key,
name char(10) not null,
address varchar(50) default '深圳',
year date
); //建表结束
//以下为插入字段
insert into teacher values('','allen','飞数科技1','2005-10-10');
insert into teacher values('','jack','飞数科技2','2005-12-23');如果你在mysql提示符键入上面
Copy after login
command is also possible, but it is inconvenient for debugging.


(1)

You can write the above command as it is into a text file, assuming it is sudu.sql, and then copy it to c:\\ and run it in DOS state Enter the directory \mysql\bin and type the following command:

mysql -uroot -p password < c:\sudu.sql

If successful, a blank line will be left blank; if there is an error, there will be a prompt. (The above command has been debugged, you only need to remove the // comment to use it).

(2) Or use mysql> source c:\sudu.sql; after entering the command line. You can also import the sudu.sql file into the database .

4. Transfer text data to the database

1. The format that text data should conform to: Field data are separated by tab keys On, null values ​​are replaced by \n. Example:

3 rose Feishu Technology 1 1976-10-10

4 mike Feisu Technology 2 1975-12-23

Suppose you save these two sets of data as a speed sudu.txt file and place it in the root directory of the c drive.

2. Data input command load data local infile "c:\sudu.txt" into table table name;

Note: You'd better copy the file to the \mysql\bin directory , and you must first use the use command to open the library where the table is located.

5. Back up the database: (The command is executed in the \mysql\bin directory of DOS)

1. Export the entire database

The export file is stored in the mysql\bin directory by default

mysqldump -u username -p database name> exported file name

mysqldump -u user_name -p123456 database_name > outfile_name .sql

2. Export a table

mysqldump -u username-p database name table name> Exported file name

mysqldump -u user_name -p database_name table_name > ; outfile_name.sql

3. Export a database structure

mysqldump -u user_name -p -d --add-drop-table database_name > outfile_name.sql

- d No data --add-drop-table Add a drop table before each create statement

4. Export with language parameters

mysqldump -uroot -p --default-character-set =latin1 --set-charset=gbk --skip-opt
database_name > outfile_name.sql

The above is the detailed content of A detailed introduction to the method of creating a MySQL database using commands. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

See all articles