1.上传或者下载包(两种方式选择一种即可)
[root@db01 ~]# rz mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz(如果采用这种上传方式,需要自行下载mysql5.6的源码包,建议用下面wget下载方式) [root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
2.安装依赖包
[root@db01 ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ cmake autoconf openssl openssl-devel
3.解压安装包
[root@db01 ~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
4.移动目录并改名
[root@db01 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.46
5.做软连接
[root@db01 ~]# ln -s /usr/local/mysql-5.6.46 /usr/local/mysql
6.创建数据库用户
[root@db01 ~]# useradd mysql -s /sbin/nologin -M
7.拷贝配置文件和启动文件
[root@db01 ~]# cd /usr/local/mysql/support-files/ #拷贝mysql默认配置文件 [root@db01 support-files]# cp my-default.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y #拷贝mysql启动脚本 [root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
8.初始化数据库
#1.进入初始化的目录 [root@db01 ~]# cd /usr/local/mysql/scripts/ [root@db01 scripts]# ll total 36 -rwxr-xr-x 1 7161 31415 34977 Sep 27 2019 mysql_install_db #2.执行初始化命令 [root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ #3.判断是否执行成功 1.执行过程中出现两个ok 2.数据目录下有新文件 ll /usr/local/mysql/data/ #数据安装好默认有四个库: mysql test performance_schema information_schema 初始化之前只有一个test库,初始化的作用就是生成其他三个库
9.启动数据库并验证服务启动
[root@db01 ~]# /etc/init.d/mysqld start Starting MySQL.Logging to '/usr/local/mysql/data/db01.err'. SUCCESS! [root@db01 ~]# ps -ef | grep [m]ysql mysql 23893 1 1 20:28 ? 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf [root@db01 ~]# netstat -lntp | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 23893/mysqld #停止数据库 [root@db01 ~]# /etc/init.d/mysqld stop Shutting down MySQL.. SUCCESS
10.配置system管理mysql
#1.配置system管理 [root@db01 ~]# vim /usr/lib/systemd/system/mysql.service [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=https://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 ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 #2.重新读取启动文件列表 [root@db01 ~]# systemctl daemon-reload #3.使用system启动MySQL [root@db01 ~]# systemctl start mysql #停止数据库命令 [root@db01 ~]# systemctl stop mysql
11.登录MySQL
#方式一: [root@db01 ~]# /usr/local/mysql/bin/mysql #方式二:配置环境变量后登录(推荐) [root@db01 ~]# vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH [root@db01 ~]# source /etc/profile [root@db01 ~]# mysql #设置root登录密码(输入两次密码,输入的时候密码是看不到的 输入请谨慎 防止输错) [root@db01 ~]#mysqladmin -uroot password

