The detailed steps of installing MySQL5.7.24 under Linux can be done at one time to avoid problems such as missing pid files

first step:

Download the MySQL installation package, which can be downloaded directly from the official website, and then uploaded to the server through tools;

You can also use the command to download on the server, enter the /usr/local directory, the command is as follows.

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

Step 2: Unzip and rename it to mysql.

tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql

Step 3: Create mysql users and user groups.

groupadd mysql
useradd -r -g mysql mysql

Step 4: Create the data folder, log folder and corresponding files.

mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/logs

Step 5: Create log files and pid files in the /usr/local/mysql/logs directory.

touch mysqld.log
touch mysqld.pid

Step 6: The focus is here, authorization , in the /usr/local directory, execute authorization. If you do not authorize, you will be prompted that you cannot find pid and other files when you start the MySQL service. In fact, the problem lies in the lack of permissions.

chown -R mysql:mysql mysql/
chmod -R 755 mysql/

Step 7: Install and initialize, specify the user, data directory, and basic directory to which the database belongs. Since the specified user is mysql, all the sixth steps are especially important.

After initialization, there will be an initial password in the command line. Be sure to remember that you will need to log in to MySQL later.

Note: Before executing the following command, go to the /etc/ directory to check whether there is a my.cnf configuration file. If so, delete or modify the name and back it up! Otherwise, there will be various problems related to PID or SOCK

/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

Step 8: Enter the /usr/local/mysql directory, copy the startup script to the resource directory and authorize it, and then add the mysqld service to the system service.

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld

Step 9: Add the mysql command to the /usr/bin directory, so that you can use the mysql -uroot -p command directly to log in data on the server later.

ln -s /usr/local/mysql/bin/mysql /usr/bin

At this point, the installation of the database is over, and you can use commands to access and change the password normally. The initial password is a string generated in step 7.

service mysql start 
mysql -uroot -p 
ALTER USER `root`@`localhost` IDENTIFIED BY 'newpassword';
flush privileges;

Enable remote connection.

update user set host="%" where user="root";
flush privileges;

Under the default installation, the my.cnf configuration file is not used, so the logs folder and the mysqld.log and mysqld.pid files created in the fourth and fifth steps are not used.

But in many cases, you need to configure mysql, such as log files, pid files, database tables are not case-sensitive, etc. At this time, the configuration in the fourth and fifth steps will work.

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
port = 3306
socket = /tmp/mysql.sock

[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

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# 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
# read_rnd_buffer_size = 2M 

skip-name-resolve
user = mysql
lower_case_table_names=1
default-storage-engine = InnoDB
explicit_defaults_for_timestamp = TRUE
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/tmp/mysql.sock
character-set-server=utf8
log-error=/usr/local/mysql/logs/mysqld.log
pid-file=/usr/local/mysql/logs/mysqld.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

#innodb_data_file_path=ibdata1:2G:autoextend
#innodb_buffer_pool_size=51200M
#innodb_log_file_size=512M
#innodb_log_files_in_group=3
#max_connections=3000
max_connections=500
#max_user_connections=800
#innodb_file_per_table=ON
#innodb_flush_log_at_trx_commit=1
#innodb_flush_method=O_DIRECT
#innodb_log_buffer_size=16M
innodb_open_files=3000

Close the service, place the file in the /etc/ directory or the /usr/local/mysql/ directory, and start the service.

service mysql stop;
service mysql start;

It is important to remind that when using the my.cnf configuration file, there will be many error prompts, such as missing pid files, etc. The main problem is the lack of permissions, so after performing the fourth and fifth steps, you must remember the sixth step to authorize .

Guess you like

Origin blog.csdn.net/kzhzhang/article/details/125184763