Method to install the mysql server under centos

  • 2020-05-24 06:18:56
  • OfStack

The project needs to re-install an mysql server on the existing server, which is quite difficult, because it was tested on my laptop before, and its system is Ubuntu. What is the path and startup mode? They are not the same, so this time, I still struggle with 1:
Now I will post the problems I encountered during the installation.
First of all, the installation of rpm format will not say much, mainly the configuration file of mysql is at: /etc/ my.cnf, which needs to be modified:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1   please   Find the 1 Ok, in this 1 Add a new rule below the line, let MySQL The default encoding is UTF-8
default-character-set = utf8   please   Add this 1 line 
 Then add the following statement to the end of the profile: 
[mysql]
default-character-set = utf8

Then I started mysql directly. I thought it was like Ubuntu. After installation, it started automatically.

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

This error was encountered before, because the mysql server failed to start due to an error or some other reason.
Then start the mysql service:

root@fsailing1 init.d]# /etc/rc.d/init.d/mysqld start
 Start the  MySQL :                                                [ determine ]
[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/mysql/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 service mysqld start and safety: /usr/bin/mysqld_safe &
By starting the suffix of the service, we can clearly see where the database is located, where the error log is,
When you're done, look at the character set problem (which I haven't figured out yet). Match or not:

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 just changed the server's character set, not the client's character set.
After modifying the my.cnf file and restarting the mysql server, we get:

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)

So that completes the configuration of the character set. Then there's the question of passwords and authorization.
View user password:

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)

There is a lot of empty user and password here, no wonder you can log on to the server without any authentication, it is very insecure. So delete those insecure users

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 you can set the existing user password: either update or set.

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 1 look foolish, did not pass md5 code encryption, forget here can only use set to set the password.

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 you do here is basically done.

Related articles: