mysql进阶
- 1.下载二进制格式的mysql软件包
[root@mr ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@mr ~]# cd /usr/src/
[root@mr src]# ls
debug kernels mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@mr src]#
- 2.创建用户和组,解压软件至/usr/local/,修改目录/usr/local/mysql的属主属组
[root@mr src]# id mysql
id: 'mysql': no such user
[root@mr src]# useradd -M -r -s /sbin/nologin mysql
[root@mr src]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)
[root@mr src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mr src]# cd /usr/local/
[root@mr local]# ll
total 0
drwxr-xr-x. 2 root root 18 Jul 7 10:28 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Jul 1 09:26 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
drwxr-xr-x. 9 root root 129 Jul 27 16:03 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 6 root root 64 Jul 7 10:28 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
[root@mr local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64'
[root@mr local]# ll
total 0
drwxr-xr-x. 2 root root 18 Jul 7 10:28 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Jul 1 09:26 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
lrwxrwxrwx. 1 root root 35 Jul 27 16:04 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Jul 27 16:03 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 6 root root 64 Jul 7 10:28 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
[root@mr local]#
[root@mr local]# chown -R mysql.mysql mysql*
[root@mr local]# ll
total 0
drwxr-xr-x. 2 root root 18 Jul 7 10:28 bin
drwxr-xr-x. 2 root root 6 May 19 2020 etc
drwxr-xr-x. 2 root root 6 May 19 2020 games
drwxr-xr-x. 2 root root 6 May 19 2020 include
drwxr-xr-x. 2 root root 6 May 19 2020 lib
drwxr-xr-x. 3 root root 17 Jul 1 09:26 lib64
drwxr-xr-x. 2 root root 6 May 19 2020 libexec
lrwxrwxrwx. 1 mysql mysql 35 Jul 27 16:04 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 mysql mysql 129 Jul 27 16:03 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 May 19 2020 sbin
drwxr-xr-x. 6 root root 64 Jul 7 10:28 share
drwxr-xr-x. 2 root root 6 May 19 2020 src
[root@mr local]#
*
1. 添加环境变量
[root@mr ~]# cd /usr/local/mysql
[root@mr mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@mr mysql]# cd bin/
[root@mr bin]# pwd
/usr/local/mysql/bin
[root@mr bin]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@mr bin]# source /etc/profile.d/mysql.sh
[root@mr bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin
[root@mr bin]# which mysql
/usr/local/mysql/bin/mysql
[root@mr bin]#
[root@mr mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
'/usr/include/mysql' -> '/usr/local/mysql/include/'
[root@mr mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/
[root@mr mysql]# ldconfig
[root@mr mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/mysql/man
*
1. 建立数据存放目录,初始化数据库
[root@mr ~]# mkdir /opt/data
[root@mr ~]# ll /opt/data/
total 0
[root@mr ~]# chown -R mysql.mysql /opt/data/
[root@mr ~]# mysqld --initialize --user mysql --datadir /opt/data/
2022-07-27T08:21:49.390169Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-27T08:21:49.520539Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-27T08:21:49.548430Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-27T08:21:49.557890Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 29732c94-0d85-11ed-925a-000c29e8e4aa.
2022-07-27T08:21:49.558494Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-27T08:21:50.271098Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-27T08:21:50.271141Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-27T08:21:50.271798Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-27T08:21:50.425296Z 1 [Note] A temporary password is generated for root@localhost: -ff3uq#Fee%k
[root@mr ~]#
[root@mr ~]# echo '-ff3uq#Fee%k' > pass
[root@mr ~]# cat pass
-ff3uq#Fee%k
*
1. 生成配置文件
[root@mr ~]# 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
*
1. 配置服务启动脚本,启动mysql
[root@mr mysql]# cd support-files/
[root@mr support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@mr support-files]# file mysql.server
mysql.server: POSIX shell script, ASCII text executable
[root@mr support-files]#
方法一:
[root@mr ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/mr.err'.
SUCCESS!
[root@mr ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
[root@mr ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!
[root@mr ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
方法二:
[root@mr ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mr ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql/
datadir=/opt/data/
[root@mr ~]# service mysqld start
Starting MySQL. SUCCESS!
[root@mr ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@mr ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
[root@mr ~]# rm -rf /etc/init.d/mysqld
[root@mr ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit mysqld.service not found.
[root@mr ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
Failed to stop mysqld.service: Unit mysqld.service not loaded.
[root@mr ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
[root@mr ~]#
[root@mr ~]# cp /usr/lib/systemd/system/sshd.service .
[root@mr ~]# ls
sshd.service
[root@mr ~]# mv sshd.service mysqld.service
[root@mr ~]# ls
mysqld.service
[root@mr ~]#vim mysqld.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@mr ~]# systemctl daemon-reload
[root@mr ~]# systemctl stop firewalld
[root@mr ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@mr ~]# vim /etc/selinux/config
SELINUX=disabled
[root@mr ~]# setenforce 0
[root@mr ~]# systemctl start mysqld
[root@mr ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 25 0.0.0.0:514 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 25 [::]:514 [::]:*
[root@mr ~]#
- 7.修改密码,使用临时密码登录
`bash
[root@mr ~]# mysql -uroot -p’-ff3uq#Fee%k’
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@mr ~]# yum whatprovides libncurses.so.5
Last metadata expiration check: 0:34:58 ago on Wed 27 Jul 2022 05:02:10 PM CST.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5
[root@mr ~]# dnf install -y ncurses-compat-libs
Last metadata expiration check: 0:35:39 ago on Wed 27 Jul 2022 05:02:10 PM CST.
Dependencies resolved.
===================================================================================
Package Arch Version Repository Size
===================================================================================
Installing:
ncurses-compat-libs x86_64 6.1-9.20180224.el8 baseos 328 k
Transaction Summary
Install 1 Package
Total download size: 328 k
Installed size: 1.0 M
Downloading Packages:
ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm 735 kB/s | 328 kB 00:00
Original: https://www.cnblogs.com/marymary/p/16526187.html
Author: 溜溜威
Title: mysql进阶
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/505138/
转载文章受原作者版权保护。转载请注明原作者出处!