//创建系统用户[root@localhost src]# useradd -r -M-s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=975(myaql) gid=973(myaql) 组=973(myaql)[root@localhost src]# ls /usr/local/
bin etc games include lib lib64 libexec sbin share src
[root@localhost~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost~]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C/usr/local/[root@localhost~]# cd /usr/local/[root@localhost local]# ls
bin games lib libexec nginx share
etc include lib64 mysql-5.7.38-linux-glibc2.12-x86_64 sbin src
[root@localhost local]# mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
bin games lib libexec nginx share
etc include lib64 mysql sbin src
//修改目录账户属主属组[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll -d mysql/
drwxr-xr-x.9 mysql mysql 1296月 2815:41 mysql///添加环境变量,叫他在那个目录找MySQL[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
//读取[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# which mysql
//有特定的目录的时候,要修改//include(头文件)//man(帮助文档)//lib(库)//bin(主程序)//设置软链接,里面有多个文件,以后好直接删除目录[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
//告诉他头文件库在那个地方[root@localhost mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
//读取配置文件[root@localhost mysql]# ldconfig
//告诉他man文档在那个地方[root@localhost mysql]# vim /etc/man_db.conf
#MANDATORY_MANPATH/usr/src/pvm3/man
#
MANDATORY_MANPATH/usr/man
MANDATORY_MANPATH/usr/share/man
MANDATORY_MANPATH/usr/local/share/man
//加上这一行MANDATORY_MANPATH/usr/local/mysql/man
#---------------------------------------------------------
# set up PATH to MANPATH mapping
# ie. what man tree holds man pages for what binary directory.//建立数据存放目录
在企业,设置数据存放目录要放在存储空间大的目录
[root@localhost~]# mkdir -p /opt/data
[root@localhost]# chown -R mysql.mysql /opt/data/[root@localhost~]# ll -d /opt/data/
drwxr-xr-x.2 mysql mysql 66月 2818:39/opt/data///mysqld 系统知道mysql在哪就不用加路径[root@localhost~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T10:40:51.279183Z 0[Warning]TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option(see documentation for more details).2022-06-28T10:40:52.695768Z 0[Warning]CA certificate ca.pem isself signed.2022-06-28T10:40:52.909685Z 1[Note]A temporary password is generated for root@localhost: jysro6OtPi)o
[root@localhost~]# echo "jysro6OtPi"> pass
[root@localhost~]#
//生成配置文件[root@localhost】 vim /etc/my.cnf
[mysqld]
basedir =/usr/local/mysql
datadir =/opt/data
socket =/tmp/mysql.sock
port =3306
pid-file =/opt/data/mysql.pid
user = mysql
skip-name-resolve
# sql-mode =STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION[root@localhost~]# cd /usr/local/mysql/support-files/[root@localhost support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@localhost support-files]# file mysql.server
mysql.server:POSIX shell script,ASCII text executable
[root@localhost support-files]# ll
总用量 24-rw-r--r--.1 mysql mysql 77311月 302021 magic
-rwxr-xr-x.1 mysql mysql 106111月 302021 mysqld_multi.server
-rwxr-xr-x.1 mysql mysql 89411月 302021 mysql-log-rotate
-rwxr-xr-x.1 mysql mysql 1057611月 302021 mysql.server
[root@localhost support-files]# cp mysql.server mysqld
[root@localhost support-files]# ll
总用量 36-rw-r--r--.1 mysql mysql 77311月 302021 magic
-rwxr-xr-x.1 root root 105766月 2818:57 mysqld
-rwxr-xr-x.1 mysql mysql 106111月 302021 mysqld_multi.server
-rwxr-xr-x.1 mysql mysql 89411月 302021 mysql-log-rotate
-rwxr-xr-x.1 mysql mysql 1057611月 302021 mysql.server
[root@localhost support-files]# chown -R mysql.mysql mysqld
[root@localhost support-files]# ll
总用量 36-rw-r--r--.1 mysql mysql 77311月 302021 magic
-rwxr-xr-x.1 mysql mysql 105766月 2818:57 mysqld
-rwxr-xr-x.1 mysql mysql 106111月 302021 mysqld_multi.server
-rwxr-xr-x.1 mysql mysql 89411月 302021 mysql-log-rotate
-rwxr-xr-x.1 mysql mysql 1057611月 302021 mysql.server
[root@localhost support-files]# vim mysqld
# If you change base dir, you must also change datadir.These may get
# overwritten by settings in the MySQL configuration files.//改这个地方
basedir=/usr/local/mysql
datadir=/opt/data
[root@localhost~]# /usr/local/mysql/support-files/mysqld start
StartingMySQL.Logging to '/opt/data/localhost.err'.SUCCESS![root@localhost~]# ss -antl
StateRecv-QSend-QLocalAddress:PortPeerAddress:PortLISTEN01280.0.0.0:1110.0.0.0:*LISTEN032192.168.122.1:530.0.0.0:*LISTEN01280.0.0.0:220.0.0.0:*LISTEN05127.0.0.1:6310.0.0.0:*LISTEN080*:3306*:*[root@localhost~]# ps -ef|grep mysqld
root 4117971019:01 pts/000:00:00/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/localhost.pid
//报错缺少东西[root@localhost~]# mysql -uroot -p'jysro6OtPi'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file:No such file or directory
//查找东西来源那个包[root@localhost~]# dnf provides libncurses.so.5UpdatingSubscriptionManagement repositories.Unable to read consumer identity
This system is not registered to RedHatSubscriptionManagement.You can use subscription-manager to register.
上次元数据过期检查:0:40:31 前,执行于 2022年06月28日 星期二 18时25分34秒。
ncurses-compat-libs-6.1-9.20180224.el8.i686 :Ncurses compatibility libraries
仓库 :base
匹配来源:
提供 : libncurses.so.5//安装包[root@localhost~]# dnf -y install ncurses-compat-libs
UpdatingSubscriptionManagement repositories.Unable to read consumer identity
This system is not registered to RedHatSubscriptionManagement.You can use subscription-manager to register.
上次元数据过期检查:0:42:51 前,执行于 2022年06月28日 星期二 18时25分34秒。
[root@localhost~]# cat pass
x7GkcGDZ0h(d
[root@localhost~]# mysql -uroot -p'x7GkcGDZ0h(d'
mysql:[Warning]Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.Commands end with ; or \g.YourMySQL connection id is2Server version:5.7.37Copyright(c)2000,2022,Oracle and/or its affiliates.Oracleis a registered trademark of OracleCorporation and/or its
affiliates.Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help.Type '\c' to clear the current input statement.
mysql>set password =password('runtime123');QueryOK,0 rows affected,1warning(0.00 sec)
mysql> quit
Bye[root@localhost~]# mysql -uroot -p'runtime123'
mysql:[Warning]Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.Commands end with ; or \g.//设置开机自启//关闭selinux[root@localhost~]# setenforce 0[root@localhost~]# vim /etc/selinux/config
[root@localhost~]# ll -Z/usr/lib/systemd/system/{sshd.service,mysqld.service}//admin_home报文 selinux无法识别,所以会报错,所有要关闭selinux-rw-r--r--.1 root root unconfined_u:object_r:admin_home_t:s0 2836月 2820:27/usr/lib/systemd/system/mysqld.service
-rw-r--r--.1 root root system_u:object_r:sshd_unit_file_t:s0 4561月 92020/usr/lib/systemd/system/sshd.service
[root@localhost~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]Description=mysqld server daemon
After=network.target sshd-keygen.target
[Service]Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HDP $MATNPID[root@localhost~]# systemctl daemon-reload
[root@localhost~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
Loaded:loaded(/usr/lib/systemd/system/mysqld.service; disabled; vendor >Active:inactive(dead)[root@localhost~]# systemctl start mysqld
[root@localhost~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
Loaded:loaded(/usr/lib/systemd/system/mysqld.service; disabled; vendor >Active:active(running) since Tue2022-06-2820:49:53CST; 1s ago
Process:512182ExecStart=/usr/local/mysql/support-files/mysqld start(cod>[root@localhost~]# systemctl enable mysqld //出现报错,后面有解决办法The unit files have no installation config(WantedBy,RequiredBy,Also,Alias
settings in the [Install] section, and DefaultInstancefor template units).This means they are not meant to be enabled using systemctl.Possible reasons for having this kind of units are:1)A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.2)A unit's purpose may be to act as a helper forsome other unit which has
a requirement dependency on it.3)A unit may be started when needed via activation(socket, path, timer,D-Bus, udev, scripted systemctl call,...).4)Incase of template units, the unit is meant to be enabled with some
instance name specified.//解决办法[root@localhost support-files]# vim /usr/lib/systemd/system/mysqld.service
[Unit]Description=mysqld server daemon
After=network.target sshd-keygen.target
[Service]Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HDP $MATNPID//添加以下3行[Install]WantedBy=multi-user.target
elias=mysqld service
//重启配置文件[root@localhost support-files]# systemctl daemon-reload
[root@localhost support-files]# systemctl restart mysqld.service
[root@localhost support-files]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.[root@localhost support-files]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost support-files]# ss -antl
StateRecv-QSend-QLocalAddress:PortPeerAddress:PortLISTEN01280.0.0.0:1110.0.0.0:*LISTEN01280.0.0.0:800.0.0.0:*LISTEN032192.168.122.1:530.0.0.0:*LISTEN01280.0.0.0:220.0.0.0:*LISTEN05127.0.0.1:6310.0.0.0:*LISTEN080*:3306*:*LISTEN0128[::]:111[::]:*LISTEN0128[::]:22[::]:*LISTEN05[::1]:631[::]:*//设置免密登录//免密登录必须要在家目录下创建[root@localhost~]# vim .my.cnf
[root@localhost~]# cat .my.cnf
[client]
user = root
password = runtime123
[root@localhost~]# mysql
Welcome to the MySQL monitor.Commands end with ; or \g.YourMySQL connection id is4Server version:5.7.37MySQLCommunityServer(GPL)Copyright(c)2000,2022,Oracle and/or its affiliates.Oracleis a registered trademark of OracleCorporation and/or its
affiliates.Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help.Type '\c' to clear the current input statement.
mysql> quit
Bye