How to create a database on MySQL command line under Linux

Source: Internet
Author: User
Tags create database mysql command line


Preferred to use Putty to connect to Linux servers for command line
Enter mysql-u+ database user-p+ Database password
Set up database user is the root password is 123, should be like the following is the correct:
Mysql-uroot-p123
-U and-P connection database users and passwords cannot have spaces in between
Below to create the database MyDatabase
Create DATABASE MyDatabase;
So a database called MyDatabase is created.
show databases; Show All Database lists
Drop DATABASE MyDatabase; Delete Database MyDatabase
So how do you exit the MySQL command line?
Enter exit at the terminal; Know completely quit MySQL command behavior stop

Attached to some of the most commonly used commands

(4) Make the TestDB database the current default database
mysql> use TestDB;
(5) Create a table in the TestDB database customers
mysql> CREATE TABLE Customers (userid int NOT NULL, username varchar () not NULL);
(6) Display the list of databases
mysql> show databases;
(7) Display the table in the database
mysql> show tables;
(8) Delete Table Customers
mysql> drop table customers;
(9) Display the structure of the Customers table
mysql> desc customers;
(10) Insert a record into the Customers table
Mysql> INSERT INTO Customers (UserID, username) VALUES (1, ' Hujiahui ');
(11) Let the operation take effect in time;
Mysql> commit;
(12) Querying records in Customers
Mysql> select * from Customers;
(12) Update the data in the table
mysql> Update customers set Username= ' Dennishu ' where userid=1;
(13) Delete the records in the table
Mysql> Delete from customers;
(14) Grant HJH user access to the database
# Grant SELECT, INSERT, UPDATE, delete on *.* to Hjh@localhost indentified by "123456";
Remarks: Hjh Is the Linux username, 123456 is access to the MySQL password
(15) with username and password login mysql
# mysql-uhjh-p123456

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.