Detailed steps for installing MySql 5.7. 21 in Linux
- 2021-10-11 19:49:30
- OfStack
Preface
The most widely used database in Linux is MySQL. This article will give you a detailed introduction to the steps of installing MySql 5.7. 21 in Linux. The steps are introduced in detail, which has a certain reference learning value for everyone's study or work. The following words are not much to say. Let's take a look at the detailed introduction.
1: Download the latest mysql package mysql-5. 7.21-linux-glibc2.12-x86_64 from mysql official website
Official download address: https://dev.mysql.com/downloads/mysql/
Download address: https://www.ofstack.com/softs/38849. html
2: Unzip the mysql compressed package in linux/usr/local/ and rename it mysql
cd /usr/local/
tar -xzvf mysql Compressed package name
3: Create user group mysql, create user mysql and add it to user group mysql with read and write permissions
groupadd mysql--Create an mysql user group
useradd-r-g mysql mysql-Create an mysql user and add it to an mysql user group
chown-R mysql mysql/--Assign myql directory access to myql users
chgrp-R mysql mysql/--The user group that changed the mysql directory belongs to the mysql group
Note:
chmod Command
Used to change the access rights of files or directories. Users use it to control access to files or directories.
chgrp Command
Change the group to which the file or directory belongs.
-R handles all files in the specified directory and its subdirectories
4: Create configuration file, save and exit
vim /etc/my.cnf
# Copy the following
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# Case insensitive
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
5: Initialize the database
# Install first 1 Under this thing, otherwise initialization may report errors
yum install libaio
# Manual editing 1 Under the log file, no need to write anything, save it directly and exit it
cd /var/log/
vim mysqld.log
: wq
chmod 777 mysqld.log
chown mysql:mysql mysqld.log
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
6: View Initial Password
cat /var/log/mysqld.log
Last line: root @ localhost: This is the initial password
7: Start the service, enter mysql, modify the initial password, and run the remote connection
# If you are prompted that you must change your password before you can operate, do the following
set password=password(' New password ');
flush privileges;
UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root');
# Then do the following to open mysql Service and setting related permissions
cd /var/run/
mkdir mysqld
chmod 777 mysqld
cd mysqld
vim mysqld.pid
chmod 777 mysqld.pid
chown mysql:mysql mysqld.pid
/usr/local/mysql/support-files/mysql.server start
/usr/local/mysql/bin/mysql -uroot -p The initial password you see above
# The following is after entering the database sql Statement
use mysql;
UPDATE `mysql`.`user` SET `Host`='%', `User`='root', `Select_priv`='Y', `Insert_priv`='Y', `Update_priv`='Y', `Delete_priv`='Y', `Create_priv`='Y', `Drop_priv`='Y', `Reload_priv`='Y', `Shutdown_priv`='Y', `Process_priv`='Y', `File_priv`='Y', `Grant_priv`='Y', `References_priv`='Y', `Index_priv`='Y', `Alter_priv`='Y', `Show_db_priv`='Y', `Super_priv`='Y', `Create_tmp_table_priv`='Y', `Lock_tables_priv`='Y', `Execute_priv`='Y', `Repl_slave_priv`='Y', `Repl_client_priv`='Y', `Create_view_priv`='Y', `Show_view_priv`='Y', `Create_routine_priv`='Y', `Alter_routine_priv`='Y', `Create_user_priv`='Y', `Event_priv`='Y', `Trigger_priv`='Y', `Create_tablespace_priv`='Y', `ssl_type`='', `ssl_cipher`='', `x509_issuer`='', `x509_subject`='', `max_questions`='0', `max_updates`='0', `max_connections`='0', `max_user_connections`='0', `plugin`='mysql_native_password', `authentication_string`='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9', `password_expired`='N', `password_last_changed`='2017-11-20 12:41:07', `password_lifetime`=NULL, `account_locked`='N' WHERE (`User`='root');
flush privileges;
8: Start up automatically
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
9: Use the service mysqld command to start/stop the service
su - mysql
service mysqld start/stop/restart
Remote user establishment
grant all privileges on *.* to ' New User Name '@'%' identified by ' New password ';
flush privileges;
Add a system path
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
Enter the user password using navicat to connect to mysql successfully!
Summarize