(i) 5, installation and configuration of MySQL

Source: Internet
Author: User
Tags reserved

Finally, of course, there is our MySQL (choose "Y" If selected)

[Email protected]:/# sudo apt-get install Mysql-server

After a long wait, my interface appeared very Sao purple, prompted to enter the MySQL root user's password, then input it, my is **********,ok, re-enter, OK

Finally, we test, MySQL is not install ... Perfect

[Email protected]:/# mysql-u root-penter password: (Enter password here)
Welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 6Server version:5.7.21-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) #, 2018, Oracl e and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql>

Then look at the database that comes with it. Perfect, MySQL installation ends here too!

Mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema | | mysql              | | performance_schema | | sys                |+---------- ----------+4 rows in Set (0.01 sec) mysql> 

Quit MySQL

Mysql>exit

The next step is our configuration MySQL

1, because the default port of MySQL is 3306, so we need to confirm that 3306 port is open

[Email protected]:/# UFW Status

And then it didn't open, so let's open it.

320W
Rule added
Rule added (V6)

I'd better check it again.

[Email protected]:/# UFW Status

OK, let's do the next step!

2. Then we'll look at the running state of MySQL.

[Email protected]:/# netstat-antup

Found is 127.0.0.1:3306, this can not, because 127.0.0.1 is the local IP, we need to open out, then we have to open it, into the MySQL configuration file (the culprit is red marked out, put this line commented out, that is, in front of this line to add a # can be annotated), you TM told me do not know how to change? Press "Insert" on the keyboard, and I'll hold Your hand and press the arrow keys and delete keys.

[Email protected]:/# cd/etc/mysql/Mysql.cnf.d[email protected]:/#ls[email protected]:/#VImysqld.conf ... [mysqld]##*Basic Settings#user=Mysqlpid-file=/var/run/mysqld/Mysqld.pidsocket=/var/run/mysqld/Mysqld.sockport=3306Basedir= /Usrdatadir=/var/lib/Mysqltmpdir= /TMPLC-messages-dir=/usr/share/Mysqlskip-external-locking## Instead of Skip-Networking The default is now- listen only on# localhostwhichIs MoreCompatible and is not Lesssecure. bind -address = 127.0.0.1## *Fine tuning# ...

This should be the end, then press "ESC" and enter ": Wq" to save the exit.

[Email protected]:/# cd/etc/mysql/MYSQL.CONF.D
[Email Protected]:/etc/mysql/mysql.conf.d#ls
mysqld.cnf Mysqld_safe_syslog.cnf
[Email protected]:/#vi mysqld.cnf
...... [mysqld]## * Basic settings#user            = mysqlpid-file        =/var/run/mysqld/mysqld.pidsocket =/var/run/ mysqld/mysqld.sockport = 3306basedir =/Usrdatadir =/var/lib/mysqltmpdir =/Tmplc-messages-dir =/usr/share/mysqlskip-external-locking## Instead of skip-Networking The default is now-listen only on# localhost which are more compatible and are not less secure.  # bind-address = 127.0.0.1# # * Fine tuning# ...          

Really is the last step, want to let the configuration take effect, also let it reboot once, do not know the command? That's it.

Service MySQL Restart

Then check the running status of MySQL and see:: 3306 I'm relieved, alas, I'm a little tired now.

[Email protected]:/# netstat-antup

Then create the required database and simply manipulate the database.

1. Enter the database

[Email protected]:/#mysql-u root-penter Password: (Enter password)
Welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connectionIDIs7Server Version:5.7. +-0ubuntu0.16.04.1(Ubuntu) Copyright (c) -,2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or Itsaffiliates. Other names trademarks of their respectiveowners. Type'Help ;'Or'\h' forHelp. Type'\c'ToClearThe current input statement.mysql>

1, we need to create a database for later tutorials to use

MySQL>Createdatabase example; (note semicolon)
Query OK, 1 row Affected (0.00 sec)

2, enter the database "example"

MySQL> use examplechanged

3. Create a data table

Mysql> Create Tablepeople ( -Idint,     -Namevarchar(Ten),     -Ageint,     -Gendervarchar(5)     - ); Query OK,0Rows Affected (0.05Sec

4. To see the structure of our data sheet

Mysql> descPeople;
+--------+-------------+------+-----+---------+-------+|Field|Type| Null | Key | Default |Extra|+--------+-------------+------+-----+---------+-------+|Id| int( One)|YES| | NULL | ||Name| varchar(Ten)|YES| | NULL | ||Age| int( One)|YES| | NULL | ||Gender| varchar(5)|YES| | NULL | |+--------+-------------+------+-----+---------+-------+4Rowsinch Set(0.01Sec

5. Take a look at our data sheet data, hmm ... No data was inserted.

MySQL>Select*fromset (0.00 sec)

6, let's try to insert the data.

MySQL>insert into people value (1,'Tom',20 ,'male'1 row affected (0.00 sec)

7. Look at the data we just inserted

Mysql> Select *  frompeople;+------+------+------+--------+|Id|Name|Age|Gender|+------+------+------+--------+|    1 |Tom|    - |Male|+------+------+------+--------+1Rowinch Set(0.00Sec

Perfect, the database operation is first here. The next thing is the highlight. -Authorization

As long as you execute the following sentence, you can create a user and grant the user permission

MySQL>Grantallprivilegeson*. *  to [Email protected] ' % '  by ' 123456 '  01 Warning (0.00 sec)

Explain:

Grant: Authorization keyword

All privileges: All permissions

*. *: All tables for all databases

MyUser: The authorized user name, which is the user name of the login

%: Indicates that all hosts can access

' 123456 ': the password of the username that is authorized, that is, the password of the login

Finally quit MySQL

Mysql>exit
Bye

At this point , (a) the task has been completed, the following is (two) of the time, Home Portal

(i) 5, installation and configuration of MySQL

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.