centos7.6安装
[[email protected] ~]# yum install wget vim -y
设置selinux为disabled
[[email protected] ~]# vim /etc/selinux/config
SELINUX=disabled
[[email protected] ~]# source /etc/selinux/config
停止firewalld防火墙(也可以不停止,开放对应端口就行,因为我们这有对外防火墙,所以为了方便直接关闭)
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl disable firewalld.service
卸载系统自带的Mariadb
[[email protected] ~]# rpm -qa|grep mariadb
[[email protected] ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
删除etc目录下的my.cnf
[[email protected] ~]# rm -rf /etc/my.cnf
安装mysql5.6
安装必要的组件
[[email protected] ~]# yum install autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel -y
下载解压mysql软件
以下链接是谷歌云盘
https://drive.google.com/open?id=1vzCURG2PnpCeSGJMmVMqfVvz40_Y-pV-
以下链接是mysql官方
[[email protected] ~]# wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[[email protected] ~]# cd /usr/local/
[[email protected] local]# wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# tar xvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# mv mysql-5.6.35-linux-glibc2.5-x86_64 mysql
执行以下命令来创建mysql用户组
[[email protected] local]# groupadd mysql
执行以下命令来创建一个用户名为mysql的用户并加入mysql用户组
[[email protected] local]# useradd -g mysql mysql
copy一份/usr/local/mysql/support-files/下的my-default.cnf文件到/etc下
进入此目录
[[email protected] mysql]# pwd
/usr/local/mysql
[[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf
配置/etc目录下的my.cnf文件
[[email protected] ~]# vim /etc/my.cnf
[mysql]
设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
设置3306端口
port = 3306
socket=/var/lib/mysql/mysql.sock
设置mysql的安装目录
basedir=/usr/local/mysql
设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
允许最大连接数
max_connections=200
服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M
创建 /var/lib/mysql文件 并赋予权限
[[email protected] mysql]# mkdir -p /var/lib/mysql
[[email protected] mysql]# chmod -R 777 /var/lib/mysql
进入安装mysql软件目录
[[email protected] mysql]# cd /usr/local/mysql
修改当前目录拥有着为mysql用户
[[email protected] mysql]# chown -R mysql:mysql ./
安装数据库
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
出现以下界面没有报错就是成功
修改当前data目录的拥有者为mysql用户
[[email protected] mysql]# chown -R mysql:mysql data
授予my.cnf最大权限
[[email protected] mysql]# chmod 777 /etc/my.cnf
复制启动脚本到资源目录
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
增加mysqld服务控制脚本执行权限
[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld
//将mysqld服务加入到系统服务
[[email protected] mysql]# chkconfig --add mysqld
检查mysqld服务是否已经生效
[[email protected] mysql]# chkconfig --list mysqld
//启动mysqld
[[email protected] mysql]# service mysqld start
Warning: World-writable config file ‘/etc/my.cnf‘ is ignored
Starting MySQL.Warning: World-writable config file ‘/etc/my.cnf‘ is ignored
Warning: World-writable config file ‘/etc/my.cnf‘ is ignored
Logging to ‘/usr/local/mysql/data/node02.err‘.
.. SUCCESS!
将mysql的bin目录加入PATH环境变量,编辑 ~/.bash_profile文件
[[email protected] mysql]# vim ~/.bash_profile
[[email protected] mysql]# tailf ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
/执行下面的命令是修改的内容立即生效:
[[email protected] mysql]# source ~/.bash_profile
以root账户登录mysql,默认是没有密码的
[[email protected] mysql]# mysql -uroot -p
设置root账户密码为123456(也可以修改成你要的密码)
mysql> use mysql;
mysql> update user set password=password(‘123456‘) where user=‘root‘ and host=‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
设置远程主机登录,注意下面的your username 和 your password改成你需要设置的用户和密码
mysql> GRANT ALL PRIVILEGES ON . TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
原文地址:https://blog.51cto.com/xia1314520ting/2417038