Create a MySQL database and a tumysql database in Ubuntu

Source: Internet
Author: User

Create a MySQL database and a tumysql database in Ubuntu

Recently, I was working on a cloud computing security system project that needed to use the MySQL database. Now I want to record the database creation steps.

 

1. Use commands to install MySQL on Ubuntu

# Sudo apt-get update

# Sudo apt-get upgrade

# Sudo apt-get-f install

1. sudo apt-get install mysql-server

2. apt-get isntall mysql-client

3. sudo apt-get install libmysqlclient-dev

NOTE: If no package is found during installation, run the sudo apt-get update command to update the package.

During the installation process, you will be prompted to set the password or something. Do not forget to set the password. After the installation is complete, run the following command to check whether the installation is successful:

Sudo netstat-tap | grep mysql

After the preceding command check, if mysql's socket is in the listen status, the installation is successful.

To log on to the mysql database, run the following command:

Mysql-u root-p

-U indicates the login user name and-p indicates the Login User Password. After the above command is entered, a prompt is displayed for entering the password. Then, you can log on to mysql by entering the password.

Note: The logon username selected in this program is lza and the password is 123456.

 

II,Create a database

Grant the user permissions under the mysql command:

Mysql> grant all on *. * TO lza @ localhost identified by '20140901 ';

Log on to and create a database, that is:

Mysql-u lza-p

123456

Mysql> create database project; note: the name of the DATABASE used in this program is project.

Query OK ,.....

Mysql> use project

Now, you can add the expected table and information to the database project. In future logon, you can specify a database at the end of the command line without using the use command, that is:

Mysql-u lza-p project

After entering the password as prompted, the system will automatically switch to the database project.

  

  

 

III,Add tables and information to the database

Create a table named unit

--

-- Create the table unit

--

Mysql> create table unit (

Id int (11) not null auto_increment,

Unit_name varchar (80) not null,

Primary key (id)

) ENGINE = InnoDB DEFAULT

CHARSET = gb2312;

Query OK ,.....

Created successfully

--

-- Populate the table 'unit'

--

Add information to the table

Insert into unit (id, unit_name) values ('1', 'xi'an University of Electronic Science and Technology ');

Insert into unit (id, unit_name) values ('2', 'northwestern University of Technology ');

Insert into unit (id, unit_name) values ('3', 'xi'an Jiaotong University ');

Query OK ,.....

After the unit table is created, run the following command to view the table:

Mysql> select * from unit;

  

Create a table named files

--

-- Create the table files

--

Mysql> create table files (

Id int (11) not null auto_increment,

Fname varchar (50) not null,

Principal varchar (10) default null,

Dean varchar (10) default null,

Instructor varchar (10) default null,

Student varchar (10) default null,

Primary key (id)

) ENGINE = InnoDB DEFAULT

CHARSET = gb2312;

Created successfully

--

-- Populate the table 'users'

--

Add information to the table

Insert into files (fname, Principal, President, teacher, student) values ('file 01', 'rwo', 'rw ', 'R', 'R ');

Insert into files (fname, Principal, President, teacher, student) values ('file 02', 'rw ', 'rw', 'rwo', 'R ');

Insert into files (fname, Principal, President, teacher, student) values ('file 03', 'R', 'rwo ', 'rw', 'R ');

Insert into files (fname, Principal, President, teacher, student) values ('file 04 ', 'rwo', 'R', 'rw ', 'R ');

Run the following command to check,

  

Create a table named users

--

-- Create the table user

--

Mysql> create table users (

Id int (11) not null auto_increment,

Loginid varchar (20) not null,

Pass_word varchar (20) not null,

Name varchar (20) not null,

Sex int (11) default null,

Unitid int (11) not null,

Title varchar (10) not null,

Primary key (id ),

Index wu_ind (unitid ),

Constraint unit_info foreign key (unitid) references unit (id) on update cascade on delete cascade

) ENGINE = InnoDB DEFAULT

CHARSET = utf8;

Created successfully

--

-- Populate the table 'users'

--

Add information to the table

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('20170101', '20160301', 'wangbaoguo ', 1101120700, 'presidents ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('123456', '123456', 'Liu po', 1101120701, 'dean ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('123456', '123456', 'zhou wei', 1101120702, 'instructor ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('123456', '123456', 'zhang Ziyun ', 1101120703, 'instructor ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('123456', '123456', 'Li qi', 1101120704, 'studen ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('20170101', '20160301', 'zhaogang ', 1101120705, 'studen ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('20170101', '20160301', 'shangguan fei', 1101120706, 'studen ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('123456', '123456', 'zhang Haoran ', 1101120710, 'principal ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('20170101', '20160301', 'litong', 1101120711, 'President ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('123456', '123456', 'White dew ', 1101120712, 'instructor ');

Insert into users (loginid, pass_word, name, sex, unitid, title) values ('20170101', '20160301', 'sunzhuo ', 1101120713, 'studen ');

Query OK ,...

Run the following command to check,

  

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.