参考资料:
https://blog.csdn.net/xx345385463/article/details/90695705
https://www.cnblogs.com/wangpeng00700/p/13539856.html
一、安装包下载并解压
1、官网地址:https://downloads.mysql.com/archives/community/
2、也可以直接在CentOS中直接下载:
[root@yanze-1 local]# pwd
/usr/local
[root@yanze-1 local]#
[root@yanze-1 local]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
3、执行命令进行解压,并重命名目录为 mysql
[root@yanze-1 local]# tar zxvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@yanze-1 local]# mv mysql-5.7.33-linux-glibc2.12-x86_64 mysql
二、创建用户及用户组
1、创建用户、用户组
[root@yanze-1 local]# groupadd mysql
[root@yanze-1 local]# useradd -r -g mysql mysql
[root@yanze-1 local]# groups mysql
mysql : mysql <!-- 这里显示用户、用户组已经创建成功-->
[root@yanze-1 local]#
2、创建目录data、tmp、log并授权
[root@yanze-1 local]# cd mysql
[root@yanze-1 mysql]# pwd
/usr/local/mysql
[root@yanze-1 mysql]# mkdir data log tmp
[root@yanze-1 mysql]# chown -R mysql:mysql ./
三、修改配置文件
修改mysql的配置文件,并将下面的配置贴进去:
[root@yanze-1 mysql]# vim /etc/my.cnf
[client]
default-character-set=utf8
port = 3306
socket = /usr/local/mysql/mysql.sock
[mysqld]
character-set-server = utf8
port = 3306
socket = /usr/local/mysql/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 128M
table_open_cache = 512
sort_buffer_size = 8M
net_buffer_length = 1M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 8M
max_connections = 1600
skip-name-resolve
log_bin = /usr/local/mysql/log/mysql-bin.log
server-id = 1
collation-server = utf8_general_ci
slow_query_log=ON
slow_query_log_file = /usr/local/mysql/log/localhost-slow.log
long_query_time = 1
wait_timeout=3600
table_definition_cache=768
query_cache_size=0
query_cache_type=0
query_cache_limit=0
innodb_strict_mode=on
innodb_stats_on_metadata=on
innodb_open_files=1024
innodb_old_blocks_time=0
innodb_concurrency_tickets=500
event_scheduler=ON
interactive_timeout=3600
innodb_lock_wait_timeout=7200
innodb_file_format = Barracuda
innodb_buffer_pool_size = 5368709120
lower_case_table_names=1
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
expire_logs_days = 7
sync_binlog = 500
innodb_flush_log_at_trx_commit=2
innodb_log_file_size=800M
bind-address=0.0.0.0
四、配置开机自启
[root@yanze-1 mysql]#
[root@yanze-1 mysql]# cd /usr/local/mysql/support-files/
[root@yanze-1 support-files]#
[root@yanze-1 support-files]# cp mysql.server /etc/init.d/mysql
[root@yanze-1 support-files]#
[root@yanze-1 support-files]# chmod +x /etc/init.d/mysql
[root@yanze-1 support-files]#
[root@yanze-1 support-files]# chkconfig --add mysql
[root@yanze-1 support-files]#
五、Mysql初始化
[root@yanze-1 /]# cd /usr/local/mysql/bin/
[root@yanze-1 bin]#
[root@yanze-1 bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@yanze-1 bin]# ./mysqld: error while loading shared libraries: libaio.so.1:
cannot open shared object file: No such File
<!-- 能看到上面报错了,提示libaio.so.1文件不存在,无法进行初始化,一般是CentOS的问题,需要自己安装这个文件-->
[root@yanze-1 bin]# yum install -y libaio
<!-- 最后会看到 Complete! 的字样,标识安装完成,然后再进行上面含有 initialize 字样的初始化操作-->
六、配置环境变量
1、进/etc/profile的编辑模式
[root@yanze-1 local]# vim /etc/profile
2、将如下内容写入后保存:( 如果你的安装目录和我的不一样,记得自己修改)
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
3、刷新配置
[root@yanze-1 local]# source /etc/profile
4、添加动态链接库路径(这一步不确定有没有实际发挥作用)
[root@yanze-1 bin]# vim /etc/ld.so.conf
七、启动、
1、启动数据库
[root@yanze-1 local]# systemctl start mysql
2、第一次登录,并修改密码
[root@yanze-1 local]# systemctl start mysql
Enter password: <!-- 这里将上面保存的密码输入后登录 -->
3、修改密码
mysql> alter user 'root'@'localhost' identified by '123456';
<!-- 这里我改的密码是123456,你们看情况改-->
八、设置客户端访问
mysql> use mysql;
mysql> select user,host from user;
mysql> update user set host ='%' where user='root';
mysql> flush privileges;
至此,大功告成,mysql已安装完。
网友评论