当前位置:网站首页>CentOS MySQL installation details
CentOS MySQL installation details
2022-06-30 09:27:00 【Orangejuicer】
Linux There are several common ways to install software on :
- Source code compilation
- Decompress the package ( It's usually tar.gz)
- Compiled installation package (RPM、DPKG etc. )
- Online installation (YUM、APT etc. )
The convenience of the above methods increases in turn , But the commonality decreases in turn , For example, download the compressed package directly for decompression , This method usually requires some additional configuration work , But as long as you master the method , Each platform is basically applicable ,YUM Simple though , But the platform is limited , Network constrained , If necessary, some specific YUM Source .
It is best to master several installation methods , In principle, if you can use simple ones, use simple ones :YUM > RPM > tar.gz > Source code
This article introduces MySQL stay CentOS The installation of the , The main steps are for reference MySQL Official documents :https://dev.mysql.com/doc/refman/5.7/en/installing.html
One 、YUM
0、 Remove installed MySQL
Check MariaDB
shell> rpm -qa|grep mariadb
mariadb-server-5.5.60-1.el7_5.x86_64
mariadb-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64
Delete mariadb
If it doesn't exist ( The above check result returns null ) Then skip step
shell> rpm -e --nodeps mariadb-server
shell> rpm -e --nodeps mariadb
shell> rpm -e --nodeps mariadb-libs
Actually yum The installation method is that you don't need to delete mariadb Of , install MySQL Will overwrite the existing mariadb
Check MySQL
shell> rpm -qa|grep mysql
Delete MySQL
If it doesn't exist ( The above check result returns null ) Then skip step
shell> rpm -e --nodeps xxx
1、 add to MySQL Yum Repository
from CentOS 7 Start ,MariaDB Become Yum The default database installation package in the source . That is to say CentOS 7 And above yum install MySQL The default installation will be MariaDB(MySQL A branch of ). If you want to install the official MySQL edition , Need to use MySQL Provided Yum Source .
download MySQL Source
Official website address :https://dev.mysql.com/downloads/repo/yum/
Check the system version :
shell> cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
Select the corresponding version to download , for example CentOS 7 Currently, check the latest on the official website Yum The download address of the source is :
https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
shell> wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
install MySQL Source
shell> sudo rpm -Uvh platform-and-version-specific-package-name.rpm
for example CentOS7 Current latest MySQL Source installation :
shell> sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
Check if the installation is successful
The successful implementation will be in /etc/yum.repos.d/ Two repo file mysql-community.repo And mysql-community-source.repo
And through yum repolist You can see mysql Related resources
shell> yum repolist enabled | grep "mysql.*-community.*"
!mysql-connectors-community/x86_64 MySQL Connectors Community 108
!mysql-tools-community/x86_64 MySQL Tools Community 90
!mysql80-community/x86_64 MySQL 8.0 Community Server 113
2、 choice MySQL edition
Use MySQL Yum Repository install MySQL, The latest stable version will be selected by default , For example, through the above MySQL If the source is installed , Default installation will select MySQL 8.0 edition , If you just want to install this version , You can skip this step directly , If not , For example, I want to install MySQL5.7 edition , Need “ Switch versions ”:
View the current MySQL Yum Repository All in MySQL edition ( Each version is in a different Repository )
shell> yum repolist all | grep mysql
Switch versions
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community
Besides using yum-config-manager outside , You can also edit /etc/yum.repos.d/mysql-community.repo file
enabled=0 Ban
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
enabled=1 Enable
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Check the currently enabled MySQL Warehouse
shell> yum repolist enabled | grep mysql
If multiple warehouses are enabled at the same time , The latest version will be selected during installation
3、 install MySQL
shell> sudo yum install mysql-community-server
This command will install MySQL The server (mysql-community-server) And its required dependencies 、 Related components , Include mysql-community-client、mysql-community-common、mysql-community-libs etc.
If the bandwidth is not enough , This step will take a long time , Please be patient ~
4、 start-up MySQL
start-up
shell> sudo systemctl start mysqld.service
CentOS 6:
shell> sudo service mysqld start
Check the status
shell> sudo systemctl status mysqld.service
CentOS 6:
shell> sudo service mysqld status
stop it
shell> sudo systemctl stop mysqld.service
CentOS 6:
shell> sudo service mysqld stop
restart
shell> sudo systemctl restart mysqld.service
CentOS 6:
shell> sudo service mysqld restart
5、 Change Password
Initial password
MySQL The super administrator account will be created after the first startup [email protected], The initial password is stored in the log file :
shell> sudo grep 'temporary password' /var/log/mysqld.log
Change the default password
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
The above prompt appears because the password is too simple , The solution is as follows :
- Use complex passwords ,MySQL The default password policy is to include numbers 、 Letters and special characters ;
- If it's just for testing , I don't want to use such a complex password , You can modify the default policy , namely validate_password_policy( as well as validate_password_length And so on ), Make it support the setting of simple password , Specific methods can be self Baidu ;
- Modify the configuration file /etc/my.cnf, add to validate_password=OFF, Save and restart MySQL
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
6、 allow root The remote access
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
7、 Set the code to utf8
View encoding
mysql> SHOW VARIABLES LIKE 'character%';
Set encoding
edit /etc/my.cnf,[mysqld] Add the following code to the node :
[mysqld]
character_set_server=utf8
init-connect='SET NAMES utf8'
8、 Set boot up
shell> systemctl enable mysqld
shell> systemctl daemon-reload
Two 、RPM
In addition to the installation process , Other steps and yum The installation method is the same , I won't repeat
0、 Delete the old version
A little
1、 download MySQL Installation package
Download address :https://dev.mysql.com/downloads/mysql/
Select the corresponding version :
shell> wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
2、 install MySQL
decompression ( Unpacking )
shell> tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-5.7.26-1.el7.x86_64.rpm
mysql-community-embedded-5.7.26-1.el7.x86_64.rpm
mysql-community-test-5.7.26-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.26-1.el7.x86_64.rpm
mysql-community-common-5.7.26-1.el7.x86_64.rpm
mysql-community-devel-5.7.26-1.el7.x86_64.rpm
mysql-community-client-5.7.26-1.el7.x86_64.rpm
mysql-community-server-5.7.26-1.el7.x86_64.rpm
We mainly install these four ( Others can be installed together if necessary ):
mysql-community-libs-5.7.26-1.el7.x86_64.rpm
mysql-community-common-5.7.26-1.el7.x86_64.rpm
mysql-community-client-5.7.26-1.el7.x86_64.rpm
mysql-community-server-5.7.26-1.el7.x86_64.rpm
If you don't want to download rpm-bundle, The official website also provides a separate rpm Download link
install
various rpm Packages are dependent , So you need to install them in a certain order , If you are prompted about the missing dependencies during installation, you should also install the corresponding packages first :
shell> rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
shell> rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
shell> rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
shell> rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
There is another simple way , You can automatically handle dependencies between packages and automatically download missing dependencies :
shell> yum install mysql-community-{
server,client,common,libs}-*
Be careful : above yum install The order needs to be in tar Each after decompression rpm Execute in the directory where the package is located , Otherwise it will become yum Mode installed , Need configuration MySQL Of yum Source and very slow , Also, the current machine supports Internet access
3、 Set up
A little
3、 ... and 、tar.gz
0、 Delete old version
A little
1、 download
Download address :https://dev.mysql.com/downloads/mysql/
Select the corresponding version :
shell> wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
2、 install & To configure :
rely on
MySQL rely on libaio library , If you don't install it first :
shell> yum install libaio
establish mysql user
A system account that does not require login , start-up MySQL This account will be used for service
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
Unzip and create links
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
shell> ln -s mysql-5.7.26-linux-glibc2.12-x86_64/ mysql
establish mysql-files Catalog
This step is not necessary , You can set secure_file_priv The value of points to the directory ( Directory used to restrict data import and export operations )
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
initialization
shell> bin/mysqld --initialize --user=mysql
The following error occurs during initialization :
error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
Because libnuma No installation ( Or the default installation is 32 position ), We need 64 Bit :
shell> yum install numactl.x86_64
Reinitialize after execution After successful initialization, one line in the returned result contains the initial password , Use it when you log in for the first time :
A temporary password is generated for [email protected]: 8M0ary878s*U
Enable SSL( Not necessary )
shell> bin/mysql_ssl_rsa_setup
start-up
shell> bin/mysqld_safe --user=mysql &
Viewing the process, you can see some default parameters , These parameters can be modified in the configuration file
shell> ps -ef | grep mysql
root 14604 12719 0 00:03 pts/0 00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql 14674 14604 0 00:03 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM_2_24_centos.err --pid-file=VM_2_24_centos.pid
Set the environment variable
Avoid every execution mysql The command should be added with the path , stay /etc/profile Add :
export PATH=$PATH:/usr/local/mysql/bin
Set to service
shell> cp support-files/mysql.server /etc/init.d/mysqld
shell> service mysqld start|stop|restart|status
Boot up
shell> chkconfig --add mysqld
shell> chkconfig --list mysqld
mysqld 0: Turn off 1: Turn off 2: open 3: open 4: open 5: open 6: Turn off
Other configuration and yum、rpm identical , I won't repeat
边栏推荐
- Get to know handler again
- Guilin robust medical acquired 100% equity of Guilin Latex to fill the blank of latex product line
- Express file download
- Flutter theme (skin) changes
- Reading notes of "Introduction to deep learning: pytoch"
- Dart basic notes
- Treatment process record of Union Medical College Hospital (Dongdan hospital area)
- Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
- Script summary
- Esp32 (6): Bluetooth and WiFi functions for function development
猜你喜欢
float
I once met a girl whom I most wanted to take care of all my life. Later... No later
Metasploit practice - SSH brute force cracking process
Pit encountered by fastjason
Evaluation standard for audio signal quality of intelligent speakers
Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())
Implementing custom drawer component in quick application
Guilin robust medical acquired 100% equity of Guilin Latex to fill the blank of latex product line
Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
Introduction to the runner of mmcv
随机推荐
Rew acoustic test (I): microphone calibration
Flink sql -- No factory implements ‘org. apache. flink. table. delegation. ExecutorFactory‘.
Opencv learning notes -day 12 (ROI region extraction and inrange() function operation)
Challenge transform() 2D
Guilin robust medical acquired 100% equity of Guilin Latex to fill the blank of latex product line
Esp32 things (VIII): music playing function of function development
Installation, use and explanation of vulnerability scanning tool OpenVAS
Microsoft. Bcl. Async usage summary -- in Net framework 4.5 project Net framework version 4.5 and above can use async/await asynchronous feature in C 5
Rew acoustic test (II): offline test
Esp32 (IX): OTA function of function development
Express の post request
Implementing custom drawer component in quick application
Opencv learning notes-day14 drawing of image geometry (rect class rotatedrect class, rectangle drawing rectangle circle drawing circular function line drawing line function ellipse drawing elliptic fu
[cmake] make command cannot be executed normally
Talking about kotlin process exception handling mechanism
Electron, which can wrap web page programs into desktop applications
Deep Learning with Pytorch-Train A Classifier
ES6 learning path (II) let & const
Research on lg1403 divisor
Niuke IOI weekly competition 20 popularization group (problem solving)