How to install mysql server in centos

Source: Internet
Author: User

The project needs to re-install a mysql server on the existing server. It is quite difficult, because it was previously tested on my laptop and its system is Ubuntu, what is the path and the startup method. They are all different, so this time I am stuck with it:
Next we will upload the problems I encountered during the installation process,
First, the rpm format installation is not much said, mainly because the mysql configuration file is at:/etc/my. cnf, which needs to be modified:
Copy codeThe Code is as follows:
[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 statement at the end of the configuration file:
[Mysql]
Default-character-set = utf8

Then I started mysql directly. I thought it was Ubuntu, And it was automatically started after installation. However, the centos is different and the service was not started, so I got an error.
Copy codeThe Code is as follows:
[Root @ fsailing1 init. d] # mysql-u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld. sock' (2)

This error was encountered before because the mysql server was not started due to an error or other reasons.
Start the mysql service:
Copy codeThe Code is 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 00:00:00 pts/1/bin/sh/usr/bin/mysqld_safe -- datadir =/var/lib/mysql -- socket =/var/lib/mysql. sock -- log-error =/var/log/mysqld. log -- pid-file =/var/run/mysqld. pid -- user = mysql
Mysql 2002 1949 1 00:00:00 pts/1/usr/libexec/mysqld -- basedir =/usr -- datadir =/var/lib/mysql -- user = mysql -- pid-file =/var /run/mysqld. pid -- skip-external-locking -- socket =/var/lib/mysql. sock
Root 2020 1101 0 00:00:00 pts/1 grep mysql

There are many startup Methods: service mysqld start and security:/usr/bin/mysqld_safe &
By starting the service suffix, we can clearly see where the database is, where the error log is,
After that, let's take a look at the Character Set Problem (I haven't figured it out yet ). Matching or not:
Copy codeThe Code is 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 is not the case. We only changed the character set of the server and did not change the character set of the client.
After modifying the my. cnf file, restart the mysql server and learn:
Copy codeThe Code is 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 completes the character set configuration. Then there is a password and authorization problem.
View user password:
Copy codeThe Code is 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)

The user and password are empty. No wonder you can log on to the server without any authentication. This is very insecure. To delete these insecure users
Copy codeThe Code is 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: update and set are supported.
Copy codeThe Code is as follows:
Mysql> update user set password = '000000' 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)

I am dumpfounded here. I didn't encrypt it with an md5 code. I can only use set to set the password here.
Copy codeThe Code is as follows:
Mysql> set password for root @ localhost = password ('20140901 ');
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)

This is basically the end of the process.

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.