欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Linux下Centos7安装Mysql5.7.19的详细教程

程序员文章站 2023-11-09 15:12:52
1.下载mysql 网址: 2.选择源码包,通用版点击下载 直接下载就可以了,不用登录 3.解压编译 tar -zxvf mysql-5...

1.下载mysql

网址:

Linux下Centos7安装Mysql5.7.19的详细教程

2.选择源码包,通用版点击下载

Linux下Centos7安装Mysql5.7.19的详细教程

直接下载就可以了,不用登录

Linux下Centos7安装Mysql5.7.19的详细教程

3.解压编译

tar -zxvf mysql-5.7.19.tar.gz
cd mysql-5.7.19.tar.gz

创建数据目录  mkdir -p /data/mysql

先用cmake编译,没有这个命令需要先yum安装

cmake -dcmake_install_prefix=/usr/local/mysql/  #这个是编译安装之后的mysql目录所在地,可自行更改
-dmysql_datadir=/data/mysql/    #这个指向数据目录
-dmysql_unix_addr=/tmp/mysql.sock
-dsysconfdir=/usr/local/mysql-5.7/conf/
-dwith_myisam_storage_engine=1
-dwith_innobase_storage_engine=1
-dwith_blackhole_storage_engine=1
-dwith_archive_storage_engine=1
-dwith_memory_storage_engine=1
-dwith_readline=1
-dmysql_tcp_port=3306
-denabled_local_infile=1
-ddefault_charset=utf8
-ddefault_collation=utf8_general_ci
-dmysql_user=mysql
-dwith_ssl=system
-dwith_zlib=system -ddownload_boost=1 -dwith_boost=/usr/local/boost #从mysql 5.7.5开始boost库是必需安装的

编译之后make && make install  漫长的等待....之后就安装完成了

安装完成之后路径/usr/local/ 下面会有一个目录 mysql,这个目录就是我编译安装设置的路径-

dcmake_install_prefix=/usr/local/mysql/

一般为了安全起见,我们都会创建一个mysql用户和mysql组,执行以下命令

#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd
-g mysql mysql

给予mysql权限

chown -r mysql:mysql mysql
#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -g mysql mysql

给予mysql权限

chown -r mysql:mysql mysql

4.接下来配置启动向,设置开机启动

配置/ect/my.cnf,如果没有my.cnf可自行新建添加 ,  仅供参考

[client]
ort = 3306
ocket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
ort = 3306
ocket = /tmp/mysql.sock
asedir = /usr/local/mysql
datadir = /data/mysql
id-file = /data/mysql/mysql.pid
user = mysql
ind-address = 0.0.0.0
erver-id = 1
init-connect = 'set names utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
ack_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4m
inlog_cache_size = 1m
max_heap_table_size = 8m
tmp_table_size = 16m
read_buffer_size = 2m
read_rnd_buffer_size = 8m
ort_buffer_size = 8m
join_buffer_size = 8m
key_buffer_size = 4m
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8m
query_cache_limit = 2m
ft_min_word_len = 4
log_bin = mysql-bi
inlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
low_query_log = 1
long_query_time = 1
low_query_log_file = /data/mysql/mysql-slow.log
erformance_schema = 0
explicit_defaults_for_timestam
#lower_case_table_names = 1
kip-external-locking
default_storage_engine = innodb
#default-storage-engine = myisam
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64m
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2m
innodb_log_file_size = 32m
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
ulk_insert_buffer_size = 8m
myisam_sort_buffer_size = 8m
myisam_max_sort_file_size = 10g
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16m
[myisamchk]
key_buffer_size = 8m
ort_buffer_size = 8m
read_buffer = 4m
write_buffer = 4m

接下来就执行初始化数据库语句:

注意 mysql_install_db 已经不再推荐使用了,建议改成 mysqld –initialize 完成实例初始化。

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

这步很重要,如果没有初始化直接启动数据库会报错

error! the server quit without updating pid file (/data/mysql/mysql.pid).

如果初始化失败或者报以下错误,就需要先清空你的/data/mysql目录了,因为mysql目录下面有数据所以初始化执行中止。

2017-08-29t13:39:47.241469z 0 [error] --initialize specified but the data directory has files in it. aborting.2017-08-29t13:39:47.241536z 0 [error] aborting

清空之后再重新初始化

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

接下来可以启动mysql了

ervice mysqld start

登录测试

/usr/local/mysql/bin/mysql -uroot -

因为初始化--initialize-insecure 是默认没有密码的所以密码不用输入直接确定就行了;

假如登录报错

error 2002 (hy000): can't connect to local mysql server through socket '/tmp/mysql.sock' (2)

检查一下你启动数据库成功没  可执行  ps -ef | grep mysql  看看进程是不是启动状态

空密码不安全所以我们还要设置密码,下面命令中的\"root\"就是设置密码区域,我的密码设置为root,可自行修改

[root@localhost local]# /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"root\" with grant option;"[root@localhost local]# /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"root\" with grant option;"

接下来再登录测试一次密码修改成功没有就完成啦!

总结

以上所述是小编给大家介绍的linux下centos7安装mysql5.7.19的详细教程,希望对大家有所帮助