1 安装好开发环境各种依赖包
yum groupinstall "Development tools"
2 安装依赖包
yum install libaio
3 新建用户组和用户
groupadd mysql
useradd mysql -g mysql
4 建立存放数据库目录
mkdir /data
5 解压包指定目录
# 使用官方二进制编译好的包(快速,不易出错) 官网下载地址:https://downloads.mysql.com/archives/community/
# 直接官方地址下载
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
# 这里使用编译好的二进制安装包
tar xf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /data
cd /data
mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql
6 开始安装
#创建data目录
mkdir -p /data/mysql/data
#更改所有者
chown -R mysql:mysql /data/mysql
#创建日志目录和文件
mkdir -p /data/mysql/logs
touch /data/mysql/logs/mysql.log
touch /data/mysql/logs/mysql-error.log
#授权mysql写入日志权限
cd /data && chown mysql.mysql mysql/logs -R
7 修改配置文件(默认路径为/etc/my.cnf),配置文件中路径要和上面安装路径一致,这里配置文件内容为示例,实际使用中还要按真实需求增改数值
vim /etc/my.cnf
#---------------- 配置文件开始 ------------------#
[client]
port=3306
socket =/data/mysql/mysql.sock
default-character-set=utf8mb4
[mysql]
socket =/data/mysql/mysql.sock
default-character-set=utf8mb4
[mysqld]
port=3306
bind-address=0.0.0.0
skip-name-resolve
basedir=/data/mysql
datadir=/data/mysql/data
pid-file=/data/mysql/mysqld.pid
socket = /data/mysql/mysql.sock
explicit_defaults_for_timestamp = true
default-time-zone = '+8:00'
#字符集
character-set-client-handshake = FALSE
character_set_filesystem = utf8mb4
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
skip-character-set-client-handshake = true
# Server Id
server-id=1
log-bin = mysql-bin
expire_logs_days=7
max_binlog_size = 1024M
#使用MySQL的功能相对少(存储过程、触发器、函数)Statement(默认)
#使用MySQL的特殊功能较多(存储过程、触发器、函数)则选择 Mixed 模式
#使用MySQL的特殊功能较多(存储过程、触发器、函数)又希望数据最大化一直,此时最好选择 Row 模式
#binlog_format=
log-bin-trust-function-creators=1
#最大连接数
back_log=600
max_connections=2000
max_connect_errors=2000
tmp_table_size=1024M
thread_cache_size=128
#日志 初始化的时候如果配置好了log,那么随机密码相关信息会写入logs中不会前台打印
general_log = ON
general_log_file = /data/mysql/logs/mysql.log
log_error = /data/mysql/logs/mysql-error.log
#慢查询
#slow_query_log = on
#slow-query-log-file = /data/mysql5.7/logs/slow-query.log
#long_query_time = 2
read_buffer_size = 8M
read_rnd_buffer_size = 8M
sort_buffer_size = 16M
table_open_cache = 2000
join_buffer_size = 32M
key_buffer_size = 256M
ft_min_word_len = 4
flush_time=0
max_allowed_packet=1024M
open_files_limit=10240
query_cache_type=0
table_definition_cache=1400
#innodb
default-storage-engine=INNODB
innodb_data_home_dir = /data/mysql/data
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_buffer_pool_size=1024M
innodb_buffer_pool_instances=1
innodb_log_file_size=256M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=600
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
#连接超时
interactive_timeout = 28800
wait_timeout = 28800
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE
[mysqldump]
quick
default-character-set = utf8mb4
max_allowed_packet = 256M
#---------------- 配置文件结束 ------------------#
8 初始化数据库
/data/mysql/bin/mysqld --user=mysql --basedir=/data/mysql/ --datadir=/data/mysql/data --initialize
#初始化后在日志文件找到mysql生产的root随机密码
cat /data/mysql/logs/mysql-error.log
2018-11-19T06:23:33.135345Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-11-19T06:23:33.135440Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
100 200
100 200
2018-11-19T06:23:34.828434Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-19T06:23:34.888319Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-19T06:23:34.948333Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a4b82a35-ebc3-11e8-adfb-0050568e526b.
2018-11-19T06:23:34.948987Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-19T06:23:34.950660Z 1 [Note] A temporary password is generated for root@localhost: E1<S.t,:_bXk
2018-11-19T06:23:35.497259Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-11-19T06:23:35.497315Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-11-19T06:23:35.497342Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-11-19T06:23:35.497365Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-11-19T06:23:35.497432Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
#拷贝启动程序文件到/etc/init.d/下面
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#修改启动脚本文件
vim /etc/init.d/mysqld
修改mysql程序路径 为我们自定义的路径
basedir=/data/mysql
datadir=/data/mysql/data
9 启动mysql
service mysqld start
[root@localhost ~]# netstat -lntp|grep mysqld
tcp 0 0 0.0.0.0:7416 0.0.0.0:* LISTEN 24253/mysqld
10 增加环境变量
vim /etc/profile
#最下面加上:
export PATH=${PATH}:/data/mysql/bin
#使环境变量生效
source /etc/profile 或者 . /etc/profile
11 修改root密码
mysql –uroot –p【密码为初始化数据库时给出的随机密码】
#修改密码,不然无法执行mysql相关命令操作;自MySQL 5.7开始,密码存在有效期的概念, 同时因为安全等级的问题,需要使用使用其它的方式进行设置。另一个需要注意的点是, 自5.7.6开始废弃了password()函数,同时无法设置old_password=1
mysql>SET PASSWORD = PASSWORD('root');
相关文章:mysql 8.0安装
本文最后记录时间 2023-10-28
文章链接地址:https://me.jinchuang.org/archives/22.html
本站文章除注明[转载|引用|来源],均为本站原创内容,转载前请注明出处
文章链接地址:https://me.jinchuang.org/archives/22.html
本站文章除注明[转载|引用|来源],均为本站原创内容,转载前请注明出处