Install MySQL on centos yum

Source: Internet
Author: User

Install MySQL.

[Root @ sample ~] # Yum-y install mysql-Server Plugin install MySQL
[Root @ sample ~] # Yum-y install PHP-mysql plugin install PHP-MySQL

Configure MySQL

[Root @ sample ~] # Vim/etc/My. CNF plugin edit the MySQL configuration file

[Mysqld]
Datadir =/var/lib/MySQL
Socket =/var/lib/MySQL. Sock
# Default to using old password format for compatibility with MySQL 3.x
# Clients (those using the mysqlclient10 compatibility package ).
Old_passwords = 1 encode find this line, add a new rule below this line, let MySQL's default code as UTF-8
Default-character-set = utf8 character add this line

Add the following statement at the end of the configuration file:

[MySQL]
Default-character-set = utf8

Start MySQL Service

[Root @ sample ~] # Chkconfig mysqld on startup

[Root @ sample ~] # Chkconfig -- list mysqld restart confirm that MySQL is started automatically
Mysqld 0: off 1: off 2: On 3: On 4: On 5: on 6: off okay if 2--5 is on

[Root @ sample ~] #/Etc/rc. d/init. d/mysqld start slave start MySQL Service

Initializing MySQL database: [OK]
Starting MYSQL: [OK]
MySQL initial Environment Settings

[1] set a password for the root user of MySQL

When MySQL was just installed, its root user was not set a password. First, set the MySQL Root Password.

[Root @ sample ~] # Mysql-u root login use the root user to log on to the MySQL server

Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 2 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> Select User, host, password from mysql. User; login view user information
+ ------ + ------------------------------ + --------------- +
| User | host | password |
+ ------ + ------------------------------ + --------------- +
| Root | localhost | the guest root password is blank.
| Root | sample.centospub.com | the guest root password is blank.
| Sample.centospub.com |
| Localhost |
| Root | % | XXX |
|
+ ------ + ------------------------------ + --------------- +

4 rows in SET (0.00 Sec)

Mysql> set password for root @ localhost = PASSWORD ('Enter the root password' here); then set the root password
Query OK, 0 rows affected (0.01 Sec)

Mysql> set password
Root @ 'sample .centospub.com '= PASSWORD ('Enter the root password' here); then set the root password.
Query OK, 0 rows affected (0.01 Sec) can be installed through the database only after this is set

Mysql> set password for root @ 'xxx' = PASSWORD ('xxx'); configure the root password
Query OK, 0 rows affected (0.01 Sec)

Mysql> Select User, host, password from mysql. User; login view user information
+ ------ + -------------------------------- + -------------------------- +
| User | host | password |
+ ------ + -------------------------------- + -------------------------- +
| Root | localhost | 19b68057189b027f | the guest root password is set.
| Root | sample.centospub.com | 19b68057189b027f | the ← root password is set.
| Sample.centospub.com |
| Localhost |
+ ------ + -------------------------------- + -------------------------- +
4 rows in SET (0.01 Sec)

Mysql> exit MySQL Server
Bye

Then, test whether the root password has taken effect.

[Root @ sample ~] # Mysql-u root login log on with a blank password

Error 1045 (28000): Access denied for user
'Root' @ 'localhost' (using password: No) indicates that the password is successfully set.

[Root @ localhost ~] # Mysql-u root-H sample.centospub.com login log on with root using an empty password

Error 1045 (28000): Access denied for user
'Root' @ 'localhost' (using password: No) indicates that the password is successfully set.

[Root @ sample ~] # Mysql-u root-P login using the password to log on as root
Enter Password: Enter password here

Welcome to the MySQL monitor. commands end with; or \ G. login confirm that you can log on with the password
Your MySQL connection ID is 5 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> exit
Bye

[Root @ sample ~] # Mysql-u root-H sample.centospub.com-P login Login login using the password Root
Enter Password: Enter password here

Welcome to the MySQL monitor. commands end with; or \ G. login confirm that you can log on with the password
Your MySQL connection ID is 6 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> exit MySQL Server
Bye

[2] deleting Anonymous Users

After MySQL is installed, a user with a blank username and password exists. This makes it possible for the database server to be logged on without a password. Delete anonymous users to eliminate potential risks.

[Root @ sample ~] # Mysql-u root-P login using the password to log on as root
Enter Password: Enter password here

Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 7 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> Select User, host from mysql. User; users view user information
+ ------ + ---------------------------- +
| User | host |
+ ------ + ---------------------------- +
| Localhost |
| Root | localhost |
| Sample.centospub.com |
| Root | sample.centospub.com |
+ ------ + ---------------------------- +
4 rows in SET (0.02 Sec)

Mysql> Delete from mysql. User where user = ''; anonymous deletes Anonymous Users
Query OK, 2 rows affected (0.17 Sec)

Mysql> Select User, host from mysql. User; users view user information
+ ------ + ---------------------------- +
| User | host |
+ ------ + ---------------------------- +
| Root | localhost |
| Root | sample.centospub.com |
+ ------ + ---------------------------- +
2 rows in SET (0.00 Sec)

Mysql> exit MySQL Server
Bye

Okay, it's not necessary!
Test MySQL

[Root @ sample ~] # Mysql-u root-P login using the password to log on as root
Enter Password: Enter password here

Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 9 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> grant all privileges on test. *
Centospub @ localhost identified by 'define the password' here; role creation has full operation on the Test Database

The user named centospub as the permission
Query OK, 0 rows affected (0.03 Sec)

Mysql> Select User From mysql. User where user = 'centospub '; confirm whether the centospub user exists.
+ --------- +
| User |
+ --------- +
| Centospub | confirm that centospub has been created
+ --------- +
1 row in SET (0.01 Sec)

Mysql> exit MySQL Server
Bye

[Root @ sample ~] # Mysql-u centospub-P login log on to the MySQL server with the newly created centospub user
Enter Password: Enter password here

Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 10 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> Create Database test; Create a database named Test
Query OK, 1 row affected (0.00 Sec)

Mysql> show databases; Databases
+ ------------- +
| Database |
+ ------------- +
| Test |
+ ------------- +
1 row in SET (0.00 Sec)

Mysql> use test environment to connect to the database
Database changed

Mysql> Create Table Test (Num int, name varchar (50); Tables create tables in the database
Query OK, 0 rows affected (0.03 Sec)

Mysql> show tables; Tables view existing tables in the database
+ ------------------- +
| Tables_in_test |
+ ------------------- +
| Test |
+ ------------------- +
1 row in SET (0.01 Sec)

Mysql> insert into test values (1, 'Hello world! '); Inserts a value into the table.
Query OK, 1 row affected (0.02 Sec)

Mysql> select * from test; Tables
+ ------ + ------------------- +
| Num | Name |
+ ------ + ------------------- +
| 1 | Hello world! |
+ ------ + ------------------- +
1 row in SET (0.00 Sec)

Mysql> Update Test Set Name = 'Hello everyone! '; Then, update the table information and assign a new value.
Query OK, 1 row affected (0.00 Sec)
Rows matched: 1 changed: 1 Warnings: 0

Mysql> select * from test; Tables
+ ------ + ---------------------- +
| Num | Name |
+ ------ + ---------------------- +
| 1 | Hello everyone! | Confirm to be updated to the new value
+ ------ + ---------------------- +
1 row in SET (0.01 Sec)

Mysql> Delete from test where num = 1; values: Delete the values in the table.
Query OK, 1 row affected (0.00 Sec)

Mysql> select * from test; confirm the deletion result
Empty set (0.01 Sec)

Mysql> drop table test; Tables Delete tables
Query OK, 0 rows affected (0.01 Sec)

Mysql> show tables; Tables
Empty set (0.00 Sec) Validation table deleted

Mysql> drop database test; Revoke Delete the database named Test
Query OK, 0 rows affected (0.01 Sec)

Mysql> show databases; Databases
Empty set (0.01 Sec) Verify that the test database has been deleted (this is a non-root user relationship, and the database named MySQL is not visible)

Mysql> exit MySQL Server
Bye

Then, delete the legacy users used for testing.

[Root @ sample ~] # Mysql-u root-P login using the password to log on as root
Enter Password: Enter password here

Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 12 to server version: 4.1.20

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> revoke all privileges on *. * from
Centospub @ localhost; Revoke revoke the database operation permissions of the centospub user
Query OK, 0 rows affected (0.00 Sec)

Mysql> Delete from mysql. User where user = 'centospub 'and host = 'localhost'; users Delete centospub users
Query OK, 1 row affected (0.01 Sec)

Mysql> Select User From mysql. User where user = 'centospub '; locate the user centospub and check whether the user has been deleted.
Empty set (0.01 Sec) validate that the centospub user does not exist

Mysql> flush privileges; volume refresh to make the above operations take effect
Query OK, 0 rows affected (0.01 Sec)

Mysql> exit
Bye

 

[Root @ sample ~] #/Etc/rc. d/init. d/httpd restart the HTTP service
Stopping httpd: [OK]
Starting httpd: [OK]

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.