Linux installs the MySQL practice using the Yum method

Source: Internet
Author: User

1. First detect if MySQL is installed

Ps-ef|grep MySQL

Root4943     1  0  -: Onepts/2    xx:xx:xx/bin/sh/usr/bin/mysqld_safe--datadir=/var/lib/mysql--socket=/var/lib/mysql/mysql.sock--pid-file=/var/run/mysqld/mysqld.pid--basedir=/usr--user=Mysqlmysql5060  4943  0  -: Onepts/2    xx:xx:xx/usr/libexec/mysqld--basedir=/usr--datadir=/var/lib/mysql--user=mysql--log-error=/var/log/mysqld.log--pid-file=/var/run/mysqld/mysqld.pid--socket=/var/lib/mysql/Mysql.sockroot5250  3079  0  -: +pts/2    xx:xx:xxMysql-u Root-Proot5289  5271  0  -: Wupts/1    xx:xx:xxgrep MySQL

If MySQL is installed, you need to uninstall MySQL first

2. Install MySQL

Yum install-y mysql-server MySQL Mysql-deve

3. Start the MySQL service

Service mysqld start//can also be started via/etc/init.d/mysqld start

4. Set to boot from startup

Chkconfig mysqld on

5. Set the password of the root account

mysqladmin-u root password ' newpwd '

6. Authorization for remote Client connection

How to use Priv_type for authorization

1. Single Authorization

GRANT priv_type on database.table to User[identified by [PASSWORD] ' PASSWORD '] [, user [identified by [PASSWORD] ' Password ' ...]

The Priv_type represents the permission to allow the operation.

Database.table represents the database name. Table Name

Note * represents all, such as database.* represents all tables for the database, *. * represents all tables for all databases
The user is composed of the username and host name (host), which is separated by @, preferably with a single quotation mark, and can be executed without adding.

2, multiple rights authorized use:

Grant permission 1, permission 2,... Permission n on the database name. Table name to User name @ user address identified by ' connection password ';

--Permissions 1, Permissions 2,... Permission n represents 14 permissions, such as Select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file.
--When Permissions 1, permissions 2,... Permission n is replaced by all privileges or all to give the user full permission.
--When the database name. The table name is replaced by *. * to give the user permission to manipulate all the tables on the server.
--The user address can be localhost, or it can be an IP address, a machine name, and a domain name. You can also use '% ' to indicate connections from any address.
--' connection password ' cannot be empty, otherwise the creation failed.

Password The password set by the representative;

Example

Grant all the permissions for all tables of all databases to the IP for any value user named Test password for PWD

GRANT all on * * to ' test ' @ '% ' identified by ' PWD ';
Authorized MyDB Database of all tables to delete and modify permissions to the IP is 1.1.1.1 User named Test password for PWD

GRANT select,insert,update,delete on mydb.* to ' test ' @ ' 1.1.1.1 ' identified by ' PWD ';
Grant the Modify permission of the Stu table of the MYDB database to the IP 1.1.1.1 User named Test password for PWD

GRANT UPDATE (name,age) on Mydb.stu to ' test ' @ ' 1.1.1.1 ' identified by ' PWD ';

Practice Authorization

Mysql-u root–p//Will prompt to enter a password, enter the above set up the root new password

GRANT all privileges on * * to ' root ' @ '% ' identified by ' newpwd ' with GRANT OPTION; *. * indicates no restrictions on connected IPs

GRANT all on * * to [e-mail protected] ' 192.168.1.4 ' identified by ' Your-root-password '; Authorizing a connection for an IP

Authorization Completion prompt content:

MySQL ' Root '@'%'testpwd' with GRANT OPTION    - >0 rows affected (0.00 sec)

If you do not need to do all the authorization how to remove the authorization? Remove the authorization to not restrict the connected IP [email protected] '% '.

mysql> drop user [email protected]'%'0 rows affected (0.00 Sec

The% here represents the object just authorized,% is all, if you need to remove an authorization, replace% with the IP that was filled in when authorized

mysql> drop user [email protected]'192.168.1.4'0 rows affected ( 0.00 sec)

If there is no authorization, there will be an error in the link, and here I take the test done by the Navicat Premium tool.

Lists the authorized user list information select * from Information_schema.user_privileges;

+--------------------+---------------+-------------------------+--------------+| GRANTEE | Table_catalog | Privilege_type | Is_grantable |+--------------------+---------------+-------------------------+--------------+|'Root'@'localhost'| NULL | SELECT | YES | |'Root'@'localhost'| NULL | INSERT | YES | |'Root'@'localhost'| NULL | UPDATE | YES | |'Root'@'localhost'| NULL | DELETE | YES | |'Root'@'localhost'| NULL | CREATE | YES | |'Root'@'localhost'| NULL | DROP | YES | |'Root'@'localhost'| NULL | RELOAD | YES | |'Root'@'localhost'| NULL | SHUTDOWN | YES | |'Root'@'localhost'| NULL | PROCESS | YES | |'Root'@'localhost'| NULL | FILE | YES | |'Root'@'localhost'| NULL | REFERENCES | YES | |'Root'@'localhost'| NULL | INDEX | YES | |'Root'@'localhost'| NULL | ALTER | YES | |'Root'@'localhost'| NULL | SHOW DATABASES | YES | |'Root'@'localhost'| NULL | SUPER | YES | |'Root'@'localhost'| NULL | CREATE Temporary TABLES | YES | |'Root'@'localhost'| NULL | LOCK TABLES | YES | |'Root'@'localhost'| NULL | EXECUTE | YES | |'Root'@'localhost'| NULL | REPLICATION SLAVE | YES | |'Root'@'localhost'| NULL | REPLICATION CLIENT | YES |
10,000 words are omitted here .....

7, set the configuration in my.cnf (file is generally in/etc/my.cnf)

[Mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socksecurity Riskssymbolic-links=0default-character-Set== 16M  Skip-name-resolve   = On  
[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
a few common configuration explanations
DataDir Default installation of the database, the default is used, special requirements can be modified installation directory
Socket Files for data interaction with a communication connection
Symbolic-links Use symbolic links to support data partitioning storage
max_connections=1000 Maximum number of connections
max_connect_errors=10000 If a user initiates a connection error that exceeds this number, the user's next connection will be blocked until the administrator executes flush hosts; An order to prevent a hacker
Back_log=50 The Accept queue, which is placed in the cache for a request queue that does not have a TCP connection, has a queue size of Back_log, limited to OS parameters
Default-character-set=utf8 Encoding format
Max_allowed_packet Limit the size of packets accepted by the server
Skip-name-resolve Prohibit Domain name resolution
Event_scheduler = On MySQL-enabled transactions (off off)

8. Restart MySQL Service

/etc/init.d/mysqld restart

9. Precautions

Flush privileges is required after setting up the user or changing the password, refresh the MySQL system permission related table, or you will receive access denied

An invalid operation after accessing IP authorization requires the use of flush privileges; Command Refresh permissions make it effective

Linux into MySQL using mysql-u root–p then enter the login password can be entered after the command input remember to bring a semicolon; Indicates a complete set of command input complete

Linux installs the MySQL practice using the Yum method

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.