# MySQL 安装手册
# 安装版本
MySQL 5.7.26
# 安装
# 下载并解压MySQL二进制安装包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.26-el7-x86_64.tar.gz
mkdir /usr/local/mysql
tar -zxf mysql-5.7.26-el7-x86_64.tar.gz -C /usr/local/mysql --strip-components=1
# 创建mysql用户、组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local/mysql
mkdir data
chmod 750 data
chown -R mysql.mysql /usr/local/mysql/
# 初始化
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 执行初始化命令后,将会打印root@localhost第一次登录的随机密码信息,如下:
# 2024-04-30T02:04:25.105428Z 1 [Note] A temporary password is generated for root@localhost: S7NdBk=qE2rg
# 生成启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
# 修改配置文件
cat > /etc/my.cnf << EOF
[mysqld]
port=3306
character-set-server = utf8
collation-server = utf8_general_ci
lower_case_table_names = 1
max_allowed_packet=64MB
max_connections=1000
innodb_large_prefix = ON
innodb_file_format = Barracuda
innodb_file_format_check = ON
innodb_file_format_max = Barracuda
innodb_file_per_table = ON
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
log-error=/var/log/mysqld.log
server_id=1
log-bin=mysql-bin
max_binlog_size=256M
binlog_format=row
EOF
# 重启服务
/etc/init.d/mysqld restart
# 配置环境变量
# 环境变量
export PATH=$PATH:/usr/local/mysql/bin
# 也可将此行加到 /etc/profile 或 ~/.bashrc 文件的末尾,然后执行 source /etc/profile 或 source ~/.bashrc 使之生效
# 修改密码
# 测试并修改root密码
[root@8a0105994ace mysql]# mysql -uroot -p'S7NdBk=qE2rg'
mysql> set password for root@localhost=password('Primeton,000');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show variables like 'validate_password%';
Empty set (0.01 sec)
mysql> exit
Bye
[root@8a0105994ace mysql]# mysql -uroot -p'Primeton,000'
mysql>
# 安装过程异常处理
异常:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install libaio -y
异常:bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
yum install numactl -y
异常:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
yum -y install libncurses*
# 参考链接
二进制包安装Mysql - 苦逼运维 - 博客园 (cnblogs.com) (opens new window)
MySQL :: Download MySQL Community Server (Archived Versions) (opens new window)