Install MySQL using yum in centos Linux

Source: Internet
Author: User
Document directory
  • Article 1: install and configure MySQL

Note: To install MySQL using yum in centos Linux, you must install MySql in a network environment. For more information about how to connect to the network in Linux, see the previous article!

Article 1: install and configure MySQL

Step 1: Install MySQL

[Root @ 192 local] # Yum-y install mysql-Server Plugin install MySQL

[Root @ 192 local] # Yum-y install PHP-mysql plugin install PHP-MySQL

 

Step 2: Configure MySQL

[Root @ 192 local] # 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

 

Article 2: Start MySQL and set the initial Environment

 

Step 1: Start the MySQL Service

[Root @ 192 local] # chkconfig mysqld on startup

[Root @ 192 local] # chkconfig -- list mysqld restart confirm MySQL is started
Mysqld 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable

Okay if 2-5 is enabled (or on)

[Root @ 192 local] #/etc/rc. d/init. d/mysqld start slave start MySQL Service

Initialize the MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
Support-files/MySQL. Server to the right place for your system

Please remember to set a password for the MySQL Root User!
To do so, start the server, then issue the following commands:
/Usr/bin/mysqladmin-u Root Password 'new-password'
/Usr/bin/mysqladmin-u root-H 192.168.0.1 password 'new-password'

Alternatively you can run:
/Usr/bin/mysql_secure_installation

Which will also give you the option of removing the test
Databases and anonymous user created by default. This is
Stronugly recommended for production servers.

See the manual for more instructions.

You can test the MySQL daemon with mysql-test-run.pl
CD mysql-test; Perl mysql-test-run.pl

Please report any problems with the/usr/bin/mysqlbug script!

The latest information about MySQL is available on the Web
Http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[OK]
Start mysqld: [OK]

Step 2: Set the initial MySQL Environment

[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 @ 192 local] # Use the root user to log on to the MySQL server when the password is not set for MySQL-u Root Login
Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 2
Server version: 5.0.95 Source Distribution

Copyright (c) 2000,201 1, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.

Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.

 

Mysql> Select User, host, password from mysql. User; login view user information
Mysql> Select User, host, password from mysql. user;
+ ------ + ------------- + ---------- +
| User | host | password |
+ ------ + ------------- + ---------- +
| Root | localhost |
| Root | 192.168.0.1 |
| Root | 127.0.0.1 |
| Localhost |
| 192.168.0.1 |
+ ------ + ------------- + ---------- +
5 rows in SET (0.03 Sec)

Mysql> set password for root @ localhost = PASSWORD ('Enter the root password' here); then set the root password

For example, in my system, I set it as follows:

Mysql> set password for root @ localhost = PASSWORD ('wangyun ');

Query OK, 0 rows affected (0.01 Sec)

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

Mysql> set password for root@127.0.0.1 = PASSWORD ('wangyun ');
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 | 5f2dfe4b07af795b |
| Root | 192.168.0.1 | 5f2dfe4b07af795b |
| Root | 127.0.0.1 | 5f2dfe4b07af795b |
| Localhost |
| 192.168.0.1 |
+ ------ + ------------- + ------------------ +
5 rows in SET (0.01 Sec)

Mysql> exit MySQL Server
Bye

 

[2] test whether the set Root Password takes effect

 

[Root @ 192 local] # mysql-u root login Log On with the root account with an empty password
Error 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: No)
When this error message appears, the password is successfully set.

[Root @ 192 local] # mysql-u root-P login Log On with the root password
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
Server version: 5.0.95 Source Distribution

......

Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.

[Root @ 192 local] # mysql-u root-H 127.0.0.1-P login Login login using the password 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 13
Server version: 5.0.95 Source Distribution

......

Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.

Mysql> exit MySQL Server
Bye

 

[3] 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 @ 192 local] # mysql-u root-P login Log On with the root password
Enter Password: Enter password here

 

Mysql> Select User, host from mysql. user;
+ ------ + ------------- +
| User | host |
+ ------ + ------------- +
| Root | 127.0.0.1 |
| 192.168.0.1 |
| Root | 192.168.0.1 |
| Localhost |
| Root | localhost |
+ ------ + ------------- +
5 rows in SET (0.03 Sec)

 

Mysql> Delete from mysql. User where user = ''; anonymous deletes Anonymous Users

Query OK, 2 rows affected (0.04 Sec)

 

Mysql> Select User, host from mysql. User; users view user information

+ ------ + ------------- +
| User | host |
+ ------ + ------------- +
| Root | 127.0.0.1 |
| Root | 192.168.0.1 |
| Root | localhost |
+ ------ + ------------- +
3 rows in SET (0.00 Sec)

 

Mysql> exit; quit to log out of the MySQL server
Bye

 

Article 3: Test

After the settings in the first and second sections, MySQL can be used properly.

Well, the content in article 3 is not necessary!
Let's test MySQL, and learn or review common SQL statements before.

[Root @ 192 local] # mysql-u centospub-P; login using the password as root
Enter Password: Enter password here

Mysql> grant all privileges on test. * tocentospub @ localhost identified by 'define the password' here ';

The role creates a user who has full permissions on the test database and is named centospub.

For example, in my system, the settings are as follows:

Mysql> grant all privileges ontest. * tocentospub @ localhost identified by 'wangyun ';


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 |
+ ----------- +
1 row in SET (0.02 Sec)

Mysql> exit;
Bye
[Root @ 192 local] # mysql-u centospub-P; login log on to the MySQL server with the newly created centospub user
Enter Password: Enter password here

 

Mysql> Create Database test; Create a database named Test
Mysql> show databases; Databases

+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Test |
+ -------------------- +
2 rows in SET (0.01 Sec)

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

Mysql> Create Table Test
-> (
-> Num int and struct: Create a table in the database.
-> Name varchar (50)
-> );
Query OK, 0 rows affected (0.14 Sec)

Mysql> show tables; Tables view existing tables in the database
+ ---------------- +
| Tables_in_test |
+ ---------------- +
| Test |
+ ---------------- +
1 row in SET (0.02 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.14 Sec)
Rows matched: 1 changed: 1 Warnings: 0

Mysql> select * from test; Tables

+ ------ + ----------------- +
| Num | Name |
+ ------ + ----------------- + Confirm to be updated to the new value
| 1 | Hello everyone! |
+ ------ + ----------------- +
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.01 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)

Confirm that the test database has been deleted (the database named MySQL is not visible because it is not the root user)

Mysql> exit MySQL Server
Bye

Then, delete the legacy users used for testing.

 

[Root @ 192 local] # mysql-u root-P;
Enter password:
Mysql> revoke all privileges on *. * From centospub @ localhost;

Revoke cancels the database operation permissions of centospub users
Query OK, 0 rows affected (0.01 Sec)

Mysql> Delete from mysql. User where user = 'centospub 'and host = 'localhost ';

← Delete a centospub user
Query OK, 1 row affected (0.14 Sec)

Mysql> Select User From mysql. User where user = 'centospub ';

Locate the centospub user 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.00 Sec)

Mysql> exit;
Bye

[Root @ 192 local] #/etc/rc. d/init. d/httpd restart the HTTP service
Note: The statement is not followed; semicolon
Stop httpd: [OK]
Start httpd: [OK]

 

 

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.