# 源
# 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/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# sudo yum install mysql-community-server
# sudo systemctl start mysqld.service
# sudo systemctl status mysqld.service
# sudo grep 'temporary password' /var/log/mysqld.log
# mysql -uroot -p
# ALTER USER 'root'@'localhost' IDENTIFIED BY 'neetest1w34!';
二进制安装方法
二进制安装 官网下载地址
2.软件包下载在/usr/src下
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
3。在/目录usr/local下解压
[root@localhost src]# tar -zxf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql-5.7.33-linux-glibc2.12-x86_64 sbin share src
4.
创建一个没有家目录,不能登录,系统的mysql普通用户
[root@localhost local]# useradd -r -M -s /sbin/nologin mysql
[root@localhost local]# id mysql
uid=974(mysql) gid=973(mysql) groups=973(mysql)
1
2
3
5.创建软连接方便操作
[root@localhost local]# ln -s mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
1
6.设置属主属组均是mysql
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll
lrwxrwxrwx. 1 mysql mysql 36 May 4 19:47 mysql -> mysql-5.7.33-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 May 4 19:42 mysql-5.7.33-linux-glibc2.12-x86_64
1
2
3
4
7.设置mysql的环境变量
[root@localhost ~]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# which mysql
/usr/local/mysql/bin/mysql
1
2
3
4
5
8.建立数据存放的目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
drwxr-xr-x. 2 mysql mysql 6 May 4 20:01 data
1
2
3
4
9.初始化数据库
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-04T12:07:43.625894Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2021-05-04T12:07:43.820483Z 0 [Warning] InnoDB: New log files created, LSN=457902021-05-04T12:07:43.847352Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2021-05-04T12:07:43.901539Z 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: 54fe2173-acd1-11eb950c-000c298d3571.2021-05-04T12:07:43.903032Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2021-05-04T12:07:44.806580Z 0 [Warning] CA certificate ca.pem is self signed.2021-05-04T12:07:44.887435Z 1 [Note] A
temporary password is generated for
root@localhost: 0%:CmR(uQoXu
#此时我的临时随机密码是:0%:CmR(uQoXu
1
2
3
4
5
10.生成配置文件
7.0版本文件是/etc/my.cnf,修改前需备份
8.0版本需自己加
[root@local ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql #安装目录
datadir = /opt/data #数据目录
socket = /tmp/mysql.sock #套接字分俩个目录 /tmp/mysql.sock或/var/lib/mysql/mysql.sock
port = 3306 #端口号
user = mysql #用户
pid-file = /opt/data/mysql.pid #进程文件
skip-name-resolve #跳过域名解析
#skip-grant-tables #跳过密码授权
#server-id=1 #服务id
#log-bin=mysql-bin #开启日志服务
1
2
3
4
5
6
7
8
9
10
11
12
11.mysql.server脚本的配置与启动
#找到mysql.server
[root@localhost support-files]# pwd
/usr/local/mysql/support-files(支持的文件)
[root@localhost support-files]# ls
magic mysqld_multi.server mysql-log-rotate (mysql.server)
#确定脚本复制到/init.d下,并且具有执行权限
[root@localhost support-files]# file mysql.server
mysql.server: POSIX shell script, ASCII text executable(脚本类型)
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/init.d/
total 36
-rw-r--r--. 1 root root 18434 Feb 15 23:09 functions
-rwxr-xr-x. 1 root root 10576 May 5 14:32 mysqld
-rw-r--r--. 1 root root 1161 Feb 1 17:04 README
#修改脚本(46,47行)
[root@localhost ~]# vim /etc/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/opt/data
#启动方法1:
[root@localhost ~]# /etc/init.d/mysqld start
[root@localhost ~]# ss -antl
LISTEN 0 80 *:3306 *:*
#启动方法2:
[root@localhost ~]# service mysqld start #版本6的方式开启
[root@localhost ~]# chkconfig mysqld on #开机自启
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12.安装 libncurses.so.5使用mysql
1.查看该包是否存在,由什么提供
[root@localhost ~]# dnf provides libncurses.so.5
Last metadata expiration check: 1:14:06 ago on Wed 05 May 2021 01:53:31 PM CST
.ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5
2.安装该包
[root@localhost ~]# dnf -y install ncurses-compat-libs
1
2
3
4
5
6
7
8
9
13.登陆,修改密码
[root@localhost ~]# mysql -uroot -p'0%:CmR(uQoXu'
mysql: [Warning] Using a password on the command line interface can be insecure
.Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates.
Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
#修改密码
mysql> set password = password(‘Huawei0917@’);
1
2
3
4
5
6
7
8
9
10
11
12
14.mysql编译创建的软连接与lib(方便使用)
#头文件include
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql
#库文件lib
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost ~]# ldconfig #读取配置文件#可以找到lib文件了
部分引用该博主的思路:Mysql 配置文件(基本配置)_DataHamal Mr.张的博客-CSDN博客