[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 at the end of the mysql database 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 for root @ 'sample .centospub.com '= password ('Enter the root password' here); configure the root password
Query OK, 0 rows affected (0.01 sec) can be installed through the database only after this is set
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
Enter password: Enter the password www.jbxue.com
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. * to centospub @ localhost identified by 'define 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 connector to connect to the database www.jbxue.com
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 View table information www.jbxue.com
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 cancels the database operation permissions of centospub users.
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]