Linux下Centos7安装Mysql5.7.19的详细教程
时间:2020-11-03 13:32 作者:admin610456
1.下载mysql/' target='_blank'>mysql
网址: https://dev.MySQL.com/downloads/mysql/
2.选择源码包,通用版点击下载
直接下载就可以了,不用登录
3.解压编译
tar -zxvf mysql-5.7.19.tar.gzcd 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 到用户组mysqluseradd-g mysql mysql
给予mysql权限
chown -R mysql:mysql mysql#添加用户组groupadd mysql#添加用户mysql 到用户组mysqluseradd -g mysql mysql
给予mysql权限
chown -R mysql:mysql mysql
4.接下来配置启动向,设置开机启动
配置/ect/my.cnf
,如果没有my.cnf可自行新建添加 , 仅供参考
[client]ort = 3306ocket = /tmp/mysql.sockdefault-character-set = utf8mb4[mysqld]ort = 3306ocket = /tmp/mysql.sockasedir = /usr/local/mysqldatadir = /data/mysqlid-file = /data/mysql/mysql.piduser = mysqlind-address = 0.0.0.0erver-id = 1init-connect = 'SET NAMES utf8mb4'character-set-server = utf8mb4#skip-name-resolve#skip-networkingack_log = 300max_connections = 1000max_connect_errors = 6000open_files_limit = 65535table_open_cache = 128max_allowed_packet = 4Minlog_cache_size = 1Mmax_heap_table_size = 8Mtmp_table_size = 16Mread_buffer_size = 2Mread_rnd_buffer_size = 8Mort_buffer_size = 8Mjoin_buffer_size = 8Mkey_buffer_size = 4Mthread_cache_size = 8query_cache_type = 1query_cache_size = 8Mquery_cache_limit = 2Mft_min_word_len = 4log_bin = mysql-biinlog_format = mixedexpire_logs_days = 30log_error = /data/mysql/mysql-error.loglow_query_log = 1long_query_time = 1low_query_log_file = /data/mysql/mysql-slow.logerformance_schema = 0explicit_defaults_for_timestam#lower_case_table_names = 1kip-external-lockingdefault_storage_engine = InnoDB#default-storage-engine = MyISAMinnodb_file_per_table = 1innodb_open_files = 500innodb_buffer_pool_size = 64Minnodb_write_io_threads = 4innodb_read_io_threads = 4innodb_thread_concurrency = 0innodb_purge_threads = 1innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 2Minnodb_log_file_size = 32Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120ulk_insert_buffer_size = 8Mmyisam_sort_buffer_size = 8Mmyisam_max_sort_file_size = 10Gmyisam_repair_threads = 1interactive_timeout = 28800wait_timeout = 28800[mysqldump]quickmax_allowed_packet = 16M[myisamchk]key_buffer_size = 8Mort_buffer_size = 8Mread_buffer = 4Mwrite_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的详细教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
(责任编辑:admin)