Install MySQL.
[Root @ sample ~] # Yum-yinstallmysql-server Plugin install MySQL
[Root @ sample ~] # Yum-yinstallphp-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
# Defaulttousingoldpasswordformatforcompatibilitywithmysql3.x
# Clients (thoseusingthemysqlclient10compatibilitypackage ).
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 ~] # Chkconfigmysqldon plugin set the MySQL service to start with the System
[Root @ sample ~] # Chkconfig -- listmysqld restart confirm that MySQL is started automatically
Mysqld0: off1: off2: on3: on4: on5: on6: off okay if 2--5 is on
[Root @ sample ~] #/Etc/rc. d/init. d/mysqldstart restart start the MySQL Service
InitializingMySQLdatabase: [OK]
StartingMySQL: [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-uroot login use the root user to log on to the MySQL server
WelcometotheMySQLmonitor. Commandsendwith; or \ g.
YourMySQLconnectionidis2toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
Mysql> selectuser, host, passwordfrommysql. user; users
+ ------ + ------------------------------ + --------------- +
| 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 rowsinset (0.00sec)
Mysql> setpasswordforroot @ localhost = password ('Enter the root password' here); then set the root password.
QueryOK, 0 rowsaffected (0.01sec)
Mysql> setpasswordforroot @ 'sample .centospub.com '= password ('Enter the root password here'); configure the root password
QueryOK, 0 rowsaffected (0.01sec) can be installed through the database only after this is set
Mysql> setpasswordforroot @ 'xxx' = password ('xxx'); configure the root password
QueryOK, 0 rowsaffected (0.01sec)
Mysql> selectuser, host, passwordfrommysql. user; users
+ ------ + -------------------------------- + -------------------------- +
| 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 rowsinset (0.01sec)
Mysql> exit MySQL Server
Bye
Then, test whether the root password has taken effect.
[Root @ sample ~] # Mysql-uroot login use a blank password to log on with the root user
ERROR1045 (28000): Accessdeniedforuser 'root' @ 'localhost' (usingpassword: NO) indicates that the password is successfully set.
[Root @ localhost ~] # Mysql-uroot-hsample.centospub.com login with a blank password with root Login
ERROR1045 (28000): Accessdeniedforuser 'root' @ 'localhost' (usingpassword: NO) indicates that the password is successfully set.
[Root @ sample ~] # Mysql-uroot-p login Login using the password root
Enterpassword: Login enter the password here
WelcometotheMySQLmonitor. Commandsendwith; or \ g. Allow: confirm that you have successfully logged on with the password.
YourMySQLconnectionidis5toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
Mysql> exit
Bye
[Root @ sample ~] # Mysql-uroot-hsample.centospub.com-p login Login with root Password
Enterpassword: Login enter the password here
WelcometotheMySQLmonitor. Commandsendwith; or \ g. Allow: confirm that you have successfully logged on with the password.
YourMySQLconnectionidis6toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
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-uroot-p login Login using the password root
Enterpassword: Login enter the password here
WelcometotheMySQLmonitor. Commandsendwith; or \ g.
YourMySQLconnectionidis7toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
Mysql> selectuser, hostfrommysql. user; users
+ ------ + ---------------------------- +
| User | host |
+ ------ + ---------------------------- +
| Localhost |
| Root | localhost |
| Sample.centospub.com |
| Root | sample.centospub.com |
+ ------ + ---------------------------- +
4 rowsinset (0.02sec)
Mysql> deletefrommysql. userwhereuser = ''; then delete Anonymous Users
QueryOK, 2 rowsaffected (0.17sec)
Mysql> selectuser, hostfrommysql. user; users
+ ------ + ---------------------------- +
| User | host |
+ ------ + ---------------------------- +
| Root | localhost |
| Root | sample.centospub.com |
+ ------ + ---------------------------- +
2 rowsinset (0.00sec)
Mysql> exit MySQL Server
Bye
Okay, it's not necessary!
Test MySQL
[Root @ sample ~] # Mysql-uroot-p login Login using the password root
Enterpassword: Login enter the password here
WelcometotheMySQLmonitor. Commandsendwith; or \ g.
YourMySQLconnectionidis9toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
Mysql> grantallprivilegesontest. * tocentospub @ localhostidentifiedby 'define password here '; role creation has full operation on the test Database
The user named centospub as the permission
QueryOK, 0 rowsaffected (0.03sec)
Mysql> selectuserfrommysql. userwhereuser = 'centospub '; confirm whether the centospub user exists.
+ --------- +
| User |
+ --------- +
| Centospub | confirm that centospub has been created
+ --------- +
1 rowinset (0.01sec)
Mysql> exit MySQL Server
Bye
[Root @ sample ~] # Mysql-ucentospub-p login log on to the MySQL server with the newly created centospub user
Enterpassword: Login enter the password here
WelcometotheMySQLmonitor. Commandsendwith; or \ g.
YourMySQLconnectionidis10toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
Mysql> createdatabasetest; Create a database named test
QueryOK, 1 rowaffected (0.00sec)
Mysql> showdatabases; Databases
+ ------------- +
| Database |
+ ------------- +
| Test |
+ ------------- +
1 rowinset (0.00sec)
Connect mysql> usetest connector to the database
Databasechanged
Mysql> createtabletest (numint, namevarchar (50); Tables create tables in the database
QueryOK, 0 rowsaffected (0.03sec)
Mysql> showtables; Tables view existing tables in the database
+ ------------------- +
| Tables_in_test |
+ ------------------- +
| Test |
+ ------------------- +
1 rowinset (0.01sec)
Mysql> insertintotestvalues (1, 'helloworld! '); Inserts a value into the table.
QueryOK, 1 rowaffected (0.02sec)
Mysql> select * fromtest; Tables
+ ------ + ------------------- +
| Num | name |
+ ------ + ------------------- +
| 1 | HelloWorld! |
+ ------ + ------------------- +
1 rowinset (0.00sec)
Mysql> updatetestsetname = 'helloeveryone! '; Then, update the table information and assign a new value.
QueryOK, 1 rowaffected (0.00sec)
Rowsmatched: 1 Changed: 1 Warnings: 0
Mysql> select * fromtest; Tables
+ ------ + ---------------------- +
| Num | name |
+ ------ + ---------------------- +
| 1 | HelloEveryone! | Confirm to be updated to the new value
+ ------ + ---------------------- +
1 rowinset (0.01sec)
Mysql> deletefromtestwherenum = 1; values: Delete the values in the table.
QueryOK, 1 rowaffected (0.00sec)
Mysql> select * fromtest; confirm the deletion result
Emptyset (0.01sec)
Mysql> droptabletest; Tables: delete a table
QueryOK, 0 rowsaffected (0.01sec)
Mysql> showtables; Tables
Emptyset (0.00sec) Validation table deleted
Mysql> dropdatabasetest; databases Delete the database named test
QueryOK, 0 rowsaffected (0.01sec)
Mysql> showdatabases; databases view existing databases
Emptyset (0.01sec) Confirm that the test database has been deleted (the relationship between non-root users is not seen here, and the database named mysql is not seen)
Mysql> exit MySQL Server
Bye
Then, delete the legacy users used for testing.
[Root @ sample ~] # Mysql-uroot-p login Login using the password root
Enterpassword: Login enter the password here
WelcometotheMySQLmonitor. Commandsendwith; or \ g.
YourMySQLconnectionidis12toserverversion: 4.1.20
Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthebuffer.
Mysql> revokeallprivilegeson *. * fromcentospub @ localhost; Revoke cancels the database operation permissions of centospub users.
QueryOK, 0 rowsaffected (0.00sec)
Mysql> deletefrommysql. userwhereuser = 'centospub 'andhost = 'localhost'; then delete the centospub user
QueryOK, 1 rowaffected (0.01sec)
Mysql> selectuserfrommysql. userwhereuser = 'centospub '; locate the user centospub and check whether the user has been deleted.
Emptyset (0.01sec) Quit to confirm that the centospub user does not exist
Mysql> flushprivileges; refresh slave to make the above operations take effect
QueryOK, 0 rowsaffected (0.01sec)
Mysql> exit
Bye
[Root @ sample ~] #/Etc/rc. d/init. d/httpdrestart restart the HTTP service
Stoppinghttpd: [OK]
Startinghttpd: [OK]