查询删除原有mysql
使用rpm -qa | grep mysql 或mariadb 搜索 mysql,如果存在,使用rpm -e --nodeps mariadb-全部删除,
或使用yum remove mysql mysql-server mysql-libs compat-mysql51全部删除;
下载所需依赖包
yum remove libnuma.so.1
yum install make cmake libaio wget -y
yum install numactl.x86_64
创建MySQL用户组和用户
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
passwd mysql
mkdir -p /data/mysql
cd /data
chown -R mysql:mysql mysql
login as mysql
cd /data/mysql
获取MySQL
地址可以查看MySQL官网
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
解压到/data/mysql
tar xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
cd mysql-8.0.17-linux-glibc2.12-x86_64
mv * ../
创建MySQL数据目录,日志目录
cd /data/mysql
mkdir data
初始化数据库
/data/mysql/bin/mysqld --initialize --basedir=/data/mysql --datadir=/data/mysql/data
2019-08-01T21:58:45.860308Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2019-08-01T21:58:45.860335Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
2019-08-01T21:58:45.866064Z 0 [System] [MY-013169] [Server] /data/mysql/bin/mysqld (mysqld 8.0.17) initializing of server in progress as process 31692
2019-08-01T21:58:49.871106Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: G2AV)PrhLD?n
2019-08-01T21:58:52.721667Z 0 [System] [MY-013170] [Server] /data/mysql/bin/mysqld (mysqld 8.0.17) initializing of server has completed
记录下最后一行mysql生成的root 临时密码: root@localhost: G2AV)PrhLD?n
ssl 验证 /data/mysql/bin/mysql_ssl_rsa_setup --datadir=/data/mysql/data
创建配置文件
vi /data/mysql/my.cnf
[mysqld]
#严格模式
sql_mode=STRICT_ALL_TABLES
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/data/mysql
# 设置mysql数据库的数据的存放目录
datadir=/data/mysql/data
# 允许最大连接数
max_connections=2000
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
#skip-log-bin
#log_bin=binlog
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
启动mysql
/data/mysql/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf &
ps -ef|grep mysql 能看到类似下面的信息,说明启动成功;
root 4578 1 0 15:16 pts/0 00:00:00 /bin/sh /data/mysql/bin/mysqld_safe --datadir=/usr/app/mysqldata --pid-file=/usr/app/mysqldata/bogon.pid
mysql 4865 4578 0 15:16 pts/0 00:00:11 /data/mysql/bin/mysqld --basedir=/data/mysql --datadir=/usr/app/mysqldata --plugin-dir=/data/mysql/lib/plugin --user=mysql --log-error=/usr/app/mysqldata/myerror.log --pid-file=/usr/app/mysqldata/bogon.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
root 5839 1022 0 15:35 pts/0 00:00:00 grep --color=auto mysql
添加环境变量
vi /home/mysql/.bash_profile
在最后添加export PATH=$PATH:/data/mysql/bin
source /home/mysql/.bash_profile
连接登录
mysql -u root -p
改密码:
alter user 'root'@'localhost' identified by 'password';
flush privileges;
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
退出关闭mysql
mysql> quit
Bye
[mysql@localhost ~]$ mysqladmin shutdown -u root -p
Enter password:
2019-08-01T22:15:02.092168Z mysqld_safe mysqld from pid file /data/mysql/data/localhost.pid ended
[1]+ Done /data/mysql/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf (wd: /data/mysql/bin)
(wd now: ~)
[mysql@localhost ~]$
ps -ef|grep mysql
[mysql@localhost ~]$ ps -ef | grep mysql
root 25031 9524 0 05:45 ? 00:00:00 sshd: mysql [priv]
mysql 25093 25031 0 05:45 ? 00:00:00 sshd: mysql@pts/2
mysql 25095 25093 0 05:45 pts/2 00:00:00 -bash
mysql 40360 25095 0 06:15 pts/2 00:00:00 ps -ef
mysql 40361 25095 0 06:15 pts/2 00:00:00 grep --color=auto mysql
[mysql@localhost ~]$
添加服务
vi /usr/lib/systemd/system/mysqld.service
#
# systemd service file for MySQL forking server
#
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Start main service
ExecStart=/data/mysql/bin/mysqld $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
加载
systemctl daemon-reload
systemctl enable mysqld.service
systemctl is-enabled mysqld
systemctl start mysqld.service