一、最小化安装系统
1) yum groupinstall ‘ Development Tools’
2) yum gropuinstall ‘base’
3) yum install lrzsz
二、安装开发工具
yum -y install gcc gcc-c++ openssl-devel
三、源码编译安装
- 上传压缩包
- 创建目录与用户 给予权限
mkdir /usr/local/mysql (mysql的目录文件)
mkdir /usr/local/mysql/data (存数据文件)
groupadd -r mysql
useradd -r -g mysql -s /bin/false -M mysql
- 编译安装
rpm -e mariadb-libs –nodeps (卸载mariadb-libs 不会卸载依赖)
1.)tar zxf cmake-3.16.0.tar.gz
cd cmake-3.16.0
./boostrap && gmake && g make install
2.)tar zxf bison-3.0.tar.gz
cd bison-3.0
./configure && make && make install
3.)tar zxf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure && make && make install
4.)tar zxf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/boots
5.)tar zxf mysql-5.7.28.tar.gz
cd mysql-5.7.28-
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DMYSQL_DATADIR=/usr/local//mysql/data/ -DSYSCONFDIR=/etc/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SYSTEMD=1 -DWITH_BOOST=/usr/local/boots
make -j 4 && make install
4.)给数据库权限
chown -R mysql:mysql /usr/local/mysql/
5.)填写配置文件
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysql.pid
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
socket=/usr/local/mysql/mysql.sock
6.)优化路径
ln -s /usr/local/mysql/bin/* /usr/local/bin/
7.)初始化数据库
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
8.)复制启动文件
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
9.)更改配置文件
10.)systemctl daemon-reload(刷新配置文件)
systemctl start mysqld
11.)查看初始数据库密码
cat /usr/local/mysql/data/mysql.err | grep password
12)登录
mysql -uroot –p
输入初始密码:
13)设置数据库密码
alter user root@localhost identified by ‘123.Com’;
四、 yum安装mysql
1.)下载mysql的yum库rpm包
2.)rpm安装
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
3.)更改下载版本
0 表示不下载
1 表示下载
2.) yum 安装数据库
yum -y install mysql-server
3.)初始化数据库
mysqld --initialize –user=mysql
4.)启动数据库
Systemctl start mysqld
5.)查看初始数据库密码
cat /usr/local/mysql/data/mysql.err | grep password
6.)登录
mysql -uroot –p
输入初始密码:
7.)设置数据库密码
alter user root@localhost identified by ‘123.Com’;
五、rpm安装
1.)卸载mariadb依赖
rpm -e mariadb-libs –nodeps (卸载mariadb-libs 不会卸载依赖)
2.)安装rpm包
1.)rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
2.)rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
3.)mysql-community-client-5.7.28-1.el7.x86_64.rpm
4.)mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
5.)mysql-community-server-5.7.28-1.el7.x86_64.rpm
3.)初始化mysql数据库
mysqld --initialize --user=’mysql’
4.)查看初始化密码
cat /usr/local/mysql/data/mysql.err | grep password
5.)登录
mysql -uroot –p
输入初始密码:
6.)设置数据库密码
alter user root@localhost identified by ‘123.Com’;