Build MySQL database in Ubuntu

Source: Internet
Author: User
Tags mysql in

A recent project on a cloud computing security system requires a MySQL database and now records the steps to build a database.

First, install MySQL on Ubuntu with the command

# 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 there are no packages found during the installation, use the command sudo apt-get update package.

During installation, you will be prompted to set a password or something, note that the settings do not forget that after the installation is complete, you can use the following command to check if the installation is successful:

sudo netstat-tap | grep MySQL

After checking with the above command, if you see a socket with MySQL in the Listen state, the installation is successful.

Log in to MySQL database by the following command:

Mysql-u root-p

-U means to select the login user name,-p indicates the login user password, the above command input will prompt for a password, then enter the password can log in to MySQL.

Note: The login user named Lza is selected in this program and the password is 123456.

Second, set up a database

Give the user permission under the MySQL command, i.e.:

Mysql>grant all on * * to [e-mail protected] identified by ' 123456 ';

Log in and create the database, which is:

Mysql-u lza-p

123456

Mysql>create DATABASE Project; Note: The database used in this program is named Project.

Query OK,.....

Mysql>use Project

Now you can add the tables and information we want in database project. In future logins, you can specify the database at the end of the command line without using the use command, which is:

Mysql-u Lza-p Project

After you press the prompt to enter your password, you will automatically switch to using database project.

  

  

Third, adding tables and information to the database

Create a table called unit

--

--Create the table unit

--

Mysql>create Table Unit (

ID Int (one) not NULL auto_increment,

Unit_name varchar () NOT NULL,

Primary KEY (ID)

) Engine=innodb DEFAULT

charset=gb2312;

Query OK,.....

Build success

--

--Populate the table ' unit '

--

Adding information to a table

INSERT into unit (id,unit_name) VALUES (' 1 ', ' Xidian University ');

INSERT into unit (id,unit_name) VALUES (' 2 ', ' Northwestern Polytechnical University ');

INSERT into unit (id,unit_name) VALUES (' 3 ', ' XI ' an Jiaotong university ');

Query OK,.....

Once the Unit table is established, the command can be used to view:

Mysql>select * from unit;

  

Create a table named files

--

--Create the table files

--

Mysql>create Table Files (

ID Int (one) not NULL auto_increment,

fname varchar () NOT NULL,

Principal varchar (+) default NULL,

Dean varchar (+) default NULL,

Teacher varchar (+) default NULL,

Student varchar (+) default NULL,

Primary KEY (ID)

) Engine=innodb DEFAULT

charset=gb2312;

Build success

--

--Populate the table ' users '

--

Adding information to a table

Insert into files (fname, principal, Dean, teacher, student) values (' File ", ' RWO ', ' RW ', ' R ', ' R ');

Insert into files (fname, principal, Dean, teacher, student) values (' File Up ', ' RW ', ' rw ', ' RWO ', ' R ');

Insert into files (fname, principal, Dean, teacher, student) values (' Documents ', ' R ', ' RWO ', ' RW ', ' R ');

Insert into files (fname, principal, Dean, teacher, student) values (' file ', ' RWO ', ' r ', ' RW ', ' R ');

Check with the command.

  

To create a table named users

--

--Create the table user

--

Mysql>create Table Users (

ID Int (one) not NULL auto_increment,

loginID varchar () NOT NULL,

Pass_word varchar () NOT NULL,

Name varchar () is not NULL,

sex int (one) default NULL,

Unitid Int (one) is not NULL,

Title varchar (ten) is 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;

Build success

--

--Populate the table ' users '

--

Adding information to a table

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120700 ', ' 123456 ', ' Paul West ', 0, 1, ' principals ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120701 ', ' 123456 ', ' Liu Bo ', 0, 1, ' Dean ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120702 ', ' 123456 ', ' Zhou Wei ', 0, 1, ' teacher ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120703 ', ' 123456 ', ' Zhang Zi Yan ', 1, 1, ' teacher ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120704 ', ' 123456 ', ' Li Qiang ', 0, 1, ' students ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120705 ', ' 123456 ', ' Zhao Gang ', 0, 1, ' students ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120706 ', ' 123456 ', ' Officer Feifei ', 1, 1, ' students ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120710 ', ' 123456 ', ' Zhang Haojan ', 0, 2, ' principals ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120711 ', ' 123456 ', ' Li Tong Zhengyang ', 0, 2, ' Dean ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120712 ', ' 123456 ', ' White Dew ', 1, 2, ' teacher ');

Insert into users (Loginid,pass_word,name,sex,unitid,title) VALUES (' 1101120713 ', ' 123456 ', ' Sun Zhuo ', 1, 2, ' students ');

Query OK,...

Check with the command.

  

Build MySQL database in Ubuntu

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.