Install mysql in Linux (CentOS6.5)
There are many ways to install software in linux. Here we use simple and convenient yum for installation.
1. Use yum to install the mysql service and client
1. Check whether yum list installed | grep mysql has been installed.
2. yum list installed | grep MYSQL
3. query results:
4. This is my installed mysql. We can use the remove method provided by yum to delete these installed mysql and related software: yum-y remove packageName
5. Delete the existing software and install it. install the mysql client: yum install packageName (mysql)
6. install mysql server: yum install mysql-server
7. install devel: yum install mysql-devel
Here mysql has been installed, but there will be some problems to start it later. Let's take a look.
Ii. mysql attribute Configuration
1. character set encoding settings. After mysql is installed, add the default-character-set = UTF-8 in [mysqld] After the configuration file is opened in vim/etc/my. cnf.
2. start mysql service: service mysqld start or/etc/init. d/mysqld start
3. Check mysql startup settings: chkconfig -- list | grepmysql
4. You may all be off. In this case, you need to add the property:
Chkconfig mysqld on # Set mysqld to on at each level. "Each level" includes 2, 3, 4, and 5 levels.
5. You can also specify the level: chkconfig -- level 35 mysql on. mysql service is automatically started when you log on at the init 35 level.
6. Check whether your settings are successful: chkconfig -- list | grep mysql
7. stop the service: service mysqld stop or/etc/init. d/mysqld stop
After the setup is complete, we can log on, but the login may not be smooth:
Iii. client access to the server
1. mysql-uroot password 123456
The ERROR 2002 Can't connect to local MySQL server through socket '/var/lib/mysql. sock' (2) may be reported.
Cause:
(1) Service not started
(2) Add the following information to vim/etc/my. cnf:
[Client]
Socket =/var/lib/mysql. sock
Exit from vim's flat mode and write the data cached by the compiler to the my. cnf configuration file to save and exit.
2. mysql-uroot-p and press Enter.
(1) mysql may be successfully accessed.
(2) If an error is reported, you do not have the permission, because you have not created a user, you cannot do anything:
Solution 1:
[1] add skip-grant-tables under mysqld of vim/etc/my. cnf (skip the form permission and directly enter mysql mode without a password)
[2] update user setpassword = password ("you password") after entering mysql mode where user = 'root ';
[3] quit; quit service mysqld restart, and then mysql should be o!
Solution 2:
[1] service mysqldstop
[2] mysqld_safe -- skip-grant-tables & mysql-uroot-p enter
[3] use mysql;
[4] update userset password = password ("newpass") whereuser = "root"; # Change password to newpassord
[5] flushprivileges; # update Permissions
[6] quit
[7] service mysqldrestart
Mysql-uroot-p new password entered