1. cd /usr/local/src
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
解压 tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
复制 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: libnuma.so.1: cannot open shared object file: No such file or directory 可能是缺少 numactl,解决方法:
yum -y install numactl
生成了临时密码
执行以下命令创建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 (直接把下面内容复制上就行)
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不区分大小写 (sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 这个简单来说就是sql语句是否严格)
lower_case_table_names = 1
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; #授权新用户
注文章转自:https://blog.csdn.net/z13615480737/article/details/80019881