Recently, we need to migrate all the applications of three Tencent cloud servers to a Docker Centos7.x image. The migration of other applications is relatively smooth, but MySQL installation encountered some problems. The systemctl/service command in the container will display the following error:

I found some solutions, but they needed to operate on the host, so I went to the container platform operator, who unfortunately said “it can’t be solved”. Instead of using the same way I used to install MySQL with yum sources, I can install MySQL with source code instead. The following document describes how I installed MySQL source code.

1. Download the MySQL

Wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.34.tar.gzCopy the code

Version description (download MySQL version description from the link above) :

  • MySQL Community Server 5.7.34
  • Source Code
  • Generic Linux (Architecture Independent)
  • With the boost version

2. Environment dependence

MySQL > install MySQL

  • cmake
  • make
  • gcc
  • gcc-c++
  • bison
  • ncurses
  • Ncurses-devel (devel is the development version)
yum -y install cmake make gcc gcc-c++ bison ncurses ncurses-devel
Copy the code

3. The installation of MySQL

3.1 unzip

Tar -zxvf mysql-boost-5.7.34.tar.gz CD mysql-5.7.34/Copy the code

3.2. Create a compile directory

mkdir configure
cd configure
Copy the code

3.3. Generate a compilation environment

cmake .. -DWITH_BOOST=.. /boost/boost_1_59_0/ -DWITH_EMBEDDED_SERVER=OFFCopy the code

3.4. Install and compile

make && make install
Copy the code

3.5. Create mysql user groups and users

groupadd mysql
useradd -g mysql mysql
Copy the code

3.6. Set permissions

The MySQL directory is /usr/local/mysql after 3.4. Installation and compilation

chown -R mysql:mysql /usr/local/mysql
Copy the code

3.7. Create my CNF

vim /etc/my.cnf
Copy the code

The contents of my.cnf are as follows:

For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [client] default - character - set = utf8mb4 / mysql  default-character-set=utf8mb4 [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock character-set-client-handshake=FALSE character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid explicit_defaults_for_timestamp=trueCopy the code

The above content can also be adjusted

3.8. Initialize the database

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql
Copy the code

I do not display the initial password. You need to successfully start the database to skip the password and enter MySQL to change the password.

3.9. Start the database

cd /usr/local/mysql/support-files
./mysql.server start
Copy the code

MySQL/systemctl/service cannot be used in MySQL/systemctl/service. MySQL/systemctl/service cannot be used in MySQL/systemctl/service.

3.10. Set logging in to MySQL

To create a soft connection, run the mysql command directly from the command line.

ln -s /usr/local/mysql/bin/mysql /usr/local/bin
Copy the code

Create soft link to/TMP /mysql.sock

ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
Copy the code

3.11. Encrypted login

Modify /etc/my.cnf to add skip-grant-tables

Restart the MySQL

cd /usr/local/mysql/support-files
./mysql.server restart
Copy the code

Access the MySQL command line without encryption

mysql
Copy the code

Changing the Login Password

use mysql;
update user set authentication_string=password('PASSWORD') where user='root';
flush privileges;
Copy the code

Finally, exit the MySQL command line, delete or comment out skip-grant-tables in /etc/my.cnf, and restart MySQL again to log in with the new password.

4. To summarize

Don’t panic, go to the log (the log path can be found in the log-error configuration of my.cnf). Through the log can not be directly solved, the log error keyword in the online search information, and then combined with their own actual situation analysis (because each information machine environment is not the same), so you can solve most of the problems. Finally, I will post links to some of the articles I referred to so that any errors that may have occurred in the above steps can be seen through these links.

References:

  1. Build CentOS7 source installation MySQL5.7:segmentfault.com/a/119000001…

  2. Docker with mysql: The error means mysqld does not have The access rights to The directory:stackoverflow.com/questions/3…

  3. Can ‘t open the lock and privilege tables: Table’ mysql. The user ‘doesn’ t exist:stackoverflow.com/questions/3…

  4. Initialize Specified but the data directory has files init. Aborting: www.cnblogs.com/ming-4/p/11…