Getting started with Linux: Create a MySQL database using the command line
Q: On a MySQL server running somewhere, how can I create and install a MySQL database through the command line?
To create a MySQL database through the command line, you can use the mysql command line client. The following describes how to create and install mysql through the MySQL command line client.
-------------------------------------- Split line --------------------------------------
Install MySQL in Ubuntu 14.04
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Build a MySQL Master/Slave server in Ubuntu 14.04
Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS
Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04
MySQL-5.5.38 universal binary Installation
-------------------------------------- Split line --------------------------------------
Step 1: Install the MySQL client
Of course, make sure that the MySQL client has been installed. If not, follow the method below.
On Debian, Ubuntu, or Linux Mint:
- $ Sudo apt-get install mysql-client
On Fedora, CentOS, or RHEL:
- $ Sudo apt-get install mysql
Step 2: log on to the MySQL server
First, you need to use the root user to log on to your MySQL database, as shown below:
- $ Mysql-u root-h <mysql-server-ip-address>-p
Note: to log on to a remote MySQL server, you must enable remote access () on the server. If you want to call a MySQL server on the same host, you can omit the "-h" parameter
- $ Mysql-u root-p
You will need to enter the password of the MySQL server. If the authentication succeeds, the MySQL prompt will appear.
Step 3: Create a MySQL database
Before entering commands in the MySQL prompt, remember that all commands end with a semicolon (otherwise, they will not be executed ). In addition, you can use uppercase letters to input commands and lowercase letters to input database objects. But that is not necessary, just for your convenience.
Now, let's create a database called xmodulo_DB:
- Mysql> create database if not exists xmodulo_DB;
Step 4: Create a database table
To achieve the purpose of the demonstration, we will create a table named posts_tbl, which will store the following information about the article:
- Article Title
- Author's name
- Author's surname
- Article available or unavailable
- Document creation date
This process is executed in two steps:
First, select the database we want to use:
- Mysql> USE xmodulo_DB;
Then, create a new table in the database:
- Mysql> create table 'posts _ tbl '(
- 'Post _ id' int unsigned not null AUTO_INCREMENT,
- 'Content' TEXT,
- 'Author _ firstname' VARCHAR (100) not null,
- 'Author _ lastname' VARCHAR (50) default null,
- 'Isenabled' TINYINT (1) not null default 1,
- 'Date' timestamp not null default CURRENT_TIMESTAMP,
- Primary key ('Post _ id ')
- ) TYPE = MYISAM;
For more details, please continue to read the highlights on the next page: