How to install Mysql server under CentOS _mysql

Source: Internet
Author: User
The project needs to reinstall a MySQL server on the existing server, it is very difficult, because it was in my notebook before the test, its system is Ubuntu, what path Ah, start the way ah. It's not the same, so this time it still makes me tangle:
Here are the problems I encountered during the installation process,
first RPM format installation is not much to say, mainly MySQL configuration file in:/etc/my.cnf here, need to modify:
Copy Code code as follows:

[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
# Default to using the old password format for compatibility with MySQL 3.x
# clients (those using the Mysqlclient10 compatibility package).
old_passwords=1← find this line, add a new rule below this line, and let MySQL's default encoding be UTF-8
Default-character-set = utf8← Add this line
Then add the following statement to the end of the text in the configuration file:
[MySQL]
Default-character-set = UTF8

Then I started MySQL directly, but also thought it was Ubuntu, after the installation automatically started, but CentOS is not the same, the service did not start so it was wrong.
Copy Code code as follows:

[Root@fsailing1 init.d]# mysql-u Root
ERROR 2002 (HY000): Can ' t connect to the local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)

This error has been encountered before, because the MySQL server did not start due to errors or other reasons.
Then start the MySQL service:
Copy Code code as follows:

Root@fsailing1 init.d]#/etc/rc.d/init.d/mysqld Start
Start MySQL: [OK]
[Root@fsailing1 init.d]# ps-ef |grep MySQL
Root 1949 1 0 22:21 pts/1 00:00:00/bin/sh/usr/bin/mysqld_safe--datadir=/var/lib/mysql--socket=/var/lib/my Sql/mysql.sock--log-error=/var/log/mysqld.log--pid-file=/var/run/mysqld/mysqld.pid--user=mysql
MySQL 2002 1949 1 22:21 pts/1 00:00:00/usr/libexec/mysqld--basedir=/usr--datadir=/var/lib/mysql--user=mysql- -pid-file=/var/run/mysqld/mysqld.pid--skip-external-locking--socket=/var/lib/mysql/mysql.sock
Root 2020 1101 0 22:21 pts/1 00:00:00 grep mysql

There are many ways to start: Service mode service mysqld start and safe way:/usr/bin/mysqld_safe &
By starting the suffix of the service we can clearly see where the database is, where the error log is,
After that, look at the character set problem (which I haven't figured out yet). Whether to match:
Copy Code code as follows:

Mysql> Show variables like ' character% ';
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | Latin1 |
| character_set_connection | Latin1 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | Latin1 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
8 rows in Set (0.00 sec)

This situation is not possible, we just changed the character set of the server, did not change the character set of the client.
After modifying the my.cnf file, after restarting the MySQL server, you know:
Copy Code code as follows:

Mysql> Show variables like ' character% ';
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
8 rows in Set (0.00 sec)

This is done, the character set is configured. Then there is the password and authorization problem.
View User password:
Copy Code code as follows:

Mysql> Select Host, user, password from user;
+-----------+------+----------+
| Host | user | password |
+-----------+------+----------+
| localhost |          Root | |
| fsailing1 |          Root | |
| 127.0.0.1 |          Root | |
|      localhost |          | |
|      fsailing1 |          | |
+-----------+------+----------+
5 rows in Set (0.00 sec)

Here users and passwords are empty, no wonder that no need for any verification can log on to the server, which is very unsafe. So to remove these insecure users,
Copy Code code as follows:

mysql> Delete from user where user= ';
Query OK, 2 rows Affected (0.00 sec)
Mysql> Select Host, user, password from user;
+-----------+------+----------+
| Host | user | password |
+-----------+------+----------+
| localhost |          Root | |
| fsailing1 |          Root | |
| 127.0.0.1 |          Root | |
+-----------+------+----------+
3 Rows in Set (0.00 sec)

Then set the existing user password: This can be done update,set.
Copy Code code as follows:

mysql> Update user set password= ' 123 ' where host= ' localhost ';
Query OK, 1 row Affected (0.00 sec)
Rows matched:1 changed:1 warnings:0
Mysql> Select Host, user, password from user;
+-----------+------+----------+
| Host | user | password |
+-----------+------+----------+
| localhost | Root | 123 |
| fsailing1 |          Root | |
| 127.0.0.1 |          Root | |
+-----------+------+----------+
3 Rows in Set (0.00 sec)

Here I see a dumbfounded, did not go through the MD5 code encryption, it is also only set for setting the password.
Copy Code code as follows:

Mysql> Set password for Root@localhost=password (' 123 ');
Query OK, 0 rows Affected (0.00 sec)
Mysql> Select Host, user, password from user;
+-----------+------+------------------+
| Host | user | password |
+-----------+------+------------------+
| localhost | Root | 773359240eb9a1d9 |
| fsailing1 |                  Root | |
| 127.0.0.1 |                  Root | |
+-----------+------+------------------+
3 Rows in Set (0.00 sec)

What we should do here is basically finished.
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.