下载源码tar包
官网地址 https://dev.mysql.com/downloads/mysql/
https://dev.mysql.com/doc/refman/5.7/en/environment-variables.html mysq的变量说明
- 安装依赖 yum install -y cmake make gcc gcc-c++ libaio ncurses ncurses-devel
cd /usr/local/src
链接:https://pan.baidu.com/s/18tSRnB7FBb7Ak9Sr665Jeg 密码:86nj 这是5.7.22版本,下载上传到服务器
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz(不能下载了)
如果上面链接不能下载,去官网找,下面的步骤都一样
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz(用这个,后续的步骤都一样)
解压 tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
将解压的复制到 /usr/local/mysql 目录 cp -r mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
2、添加系统mysql组和mysql用户
添加系统mysql组 groupadd mysql
添加mysql用户 useradd -r -g mysql mysql (添加完成后可用id mysql查看)
3、安装数据库
切到mysql目录 cd /usr/local/mysql
修改当前目录拥有者为mysql用户 chown -R mysql:mysql ./
安装数据库 bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
生成了临时密码
(看到有的报这个错
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方法**:yum install -y libaio** //安装后在初始化就OK了)
执行以下命令创建RSA private key (图在最后)
bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
修改当前目录拥有者为mysql用户 chown -R mysql:mysql ./
修改当前data目录拥有者为mysql用户 chown -R mysql:mysql data
4**、配置my.cnf**
vim /etc/my.cnf (直接把下面内容复制上就行)
character_set_server=utf8
init_connect='SET NAMES utf8'
datadir=/usr/local/mysql/data
lower_case_table_names = 1
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
添加开机启动 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改 vim /etc/init.d/mysqld
添加路径 在46行
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
5、启动mysql service mysqld start
加入开机起动 chkconfig --add mysqld
6、登录修改密码 mysql -uroot -p 上面初始化时的密码
如果出现错误 需要添加软连接 ln -s /usr/local/mysql/bin/mysql /usr/bin
第一件事先修改密码
alter user ‘root’@‘localhost’ identified by ‘root’;
flush privileges; #刷新权限
GRANT ALL PRIVILEGES ON . TO ‘root1’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION; #授权新用户
至此安装完毕。