Centos5.3 online installation mysql
Two, configuration
[ root@sample ~]# vi /etc/my.cnf ← Edit MySQL configuration file
[ mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1 ← Find this line, add a new rule below this line to make MySQL default encoding to UTF-8
default-character-set = gbk ← add this line
Then add the following statement at the end of the configuration file:
[ mysql]
default-character-set = gbk
Three, start the MySQL service
[ root@sample ~]# chkconfig mysqld on ← Set the MySQL service to start automatically when the system starts
[ root@sample ~]# chkconfig --list mysqld ← Confirm that MySQL starts automatically
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← If 2--5 is on, it is OK
[ root@sample ~]# /etc/rc.d/init.d/mysqld start ← Start MySQL service
Start mysql [OK]
Note: If the execution of this part fails, it may be because there is no database file in /var/lib/mysql, it will report [Fatal error: Can't open and lock privilege tables: Table'mysql.host' doesn't exist], which is You need to execute the mysql_install_db command to be OK.
Four, MySQL root user set password
When MySQL was first installed, its root user was not given a password. First, set the MySQL root password.
[ root@sample ~]# mysql -u root ← Log in to the MySQL server as the root user
mysql> select user,host,password from mysql.user; ← View user information
mysql>set password for root@localhost=password('Fill in root password here'); ← set root password
mysql>set password for root@domain name=password('Fill in the root password here');
mysql> delete from mysql.user where user=''; ← delete anonymous users
mysql> exit ← Exit MySQL server [Test whether the set password is correct]
Five, delete the test database
mysql> show databases; ← View existing databases in the system
mysql> drop database test; ← delete the empty database named test
[ root@sample ~]# mysql -u root -p ← login with root by password
Enter password: ← Enter password here
mysql> grant all privileges on test.* to sleinetpub@localhost identified by'Define the password here'; ← Create a user named sleinetpub with full operation permissions on the test database
mysql> select user from mysql.user where user='sleinetpub'; ← Confirm the existence of sleinetpub user
mysql> exit ← Exit the MySQL server
[ root@sample ~]# mysql -u sleinetpub -p ← Log in to the MySQL server with the newly created sleinetpub user
Enter password: ← Enter password here
mysql> create database test; ← Create a database named test
mysql> show databases; ← View existing databases in the system
mysql> use test ← connect to the database
mysql> create table test(num int, name varchar(50)); ← Create a table in the database
mysql> show tables; ← View existing tables in the database
mysql> drop table test; ← delete table
mysql> show databases; ← View existing databases
Empty set (0.01 sec) ← Confirm that the test database has been deleted (there is a non-root user relationship, and the database named mysql cannot be seen)
mysql> exit ← Exit the MySQL server
Seven, delete the legacy users used in the test
[ root@sample ~]# mysql -u root -p ← login with root by password
Enter password: ← Enter password here
mysql> revoke all privileges on . from sleinetpub@localhost; ← cancel user sleinetpub's operation authority on the database
mysql> delete from mysql.user where user='sleinetpub' and host='localhost'; ← delete sleinetpub user
mysql> select user from mysql.user where user='sleinetpub'; ← Find user sleinetpub, confirm whether it has been deleted or not
Empty set (0.01 sec) ← Confirm that the sleinetpub user no longer exists
mysql> flush privileges; ← refresh to make the above operations take effect
mysql> exit
[ root@undefined /]# /etc/rc.d/init.d/mysqld stop ← Stop HTTP service
Stop mysql [OK]
[ root@undefined /]# /etc/rc.d/init.d/mysqld start ← start HTTP service
Start mysql [OK]
Recommended Posts