Getting started with Linux: Create a MySQL database using the command line

Source: Internet
Author: User
Tags mysql command line linux mint

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:

  1. $ Sudo apt-get install mysql-client

On Fedora, CentOS, or RHEL:

  1. $ 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:

  1. $ 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

  1. $ 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:

  1. 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:

  1. Mysql> USE xmodulo_DB;

Then, create a new table in the database:

  1. Mysql> create table 'posts _ tbl '(
  2. 'Post _ id' int unsigned not null AUTO_INCREMENT,
  3. 'Content' TEXT,
  4. 'Author _ firstname' VARCHAR (100) not null,
  5. 'Author _ lastname' VARCHAR (50) default null,
  6. 'Isenabled' TINYINT (1) not null default 1,
  7. 'Date' timestamp not null default CURRENT_TIMESTAMP,
  8. Primary key ('Post _ id ')
  9. ) TYPE = MYISAM;

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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: 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.