centos安装MySQL5.7.18详细步骤
这篇文章给大家分享的是centos安装MySQL5.7.18的详细安装教程,相信大部分人都还不知道怎么安装,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。
1、首先安装依赖包
yum install -y gcc gcc-c++ ncurses-devel perl openssl-devel
最最重要的是,不要忘了安装openssl-devel
2、安装cmake
tar -xzvf cmake-3.8.1.tar.gz cd cmake-3.8.1 ./bootstrapmake && make install
3、安装MySQL5.7.18
首先下载安装包,本人的安装版本是:mysql-boost-5.7.18.tar.gz
需要下载boost,本人配套的是boost_1_59_0版本
下载,并在/usr/local目录下解压,并重命名为boost
首先为添加 MySQL 对应的系统账户,用于保证其本地文件权限分配:
groupadd mysqluseradd -r -g mysql mysql
创建数据库目录:
mkdir -p /var/mysql/datachown mysql:mysql /var/mysql/data
进入解压后的MySQL安装包:
cd mysql-boost-5.7.18cmake . \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \-DINSTALL_DATADIR=/usr/local/mysql/data/master \-DSYSCONFDIR=/usr/local/mysql/etc \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=all \-DWITH_SSL=system \-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \-DMYSQL_USER=mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \-DDOWNLOAD_BOOST=1 \-DWITH_BOOST=/usr/local/boost
如果发生错误,修改好后,需要删除当前目录下的CMakeCache.txt文件,再重新cmake
make && make install
进行完以上步骤,需要改变 mysql 安装目录的所有者,比如我们安装的目录是 /usr/local/mysql,使用命令
chown -R mysql:mysql /usr/local/mysql
修改目录所有者。此时,复制一份默认配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
博主安装完成没有my-default.cnf 这个文件,需要自己创建,附上文件的内容:
#For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the# *** default location during install, and will be replaced if you# *** upgrade to a newer version of MySQL.[mysqld]#aracter_set_server=utf8#init_connect='SET NAMES utf8' sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 一般配置选项basedir = /usr/local/mysqldatadir = /usr/local/mysql/data/masterport = 3306socket = /usr/local/mysql/data/mysql.sockcharacter-set-server=utf8back_log = 300max_connections = 3000max_connect_errors = 50table_open_cache = 4096max_allowed_packet = 32M#binlog_cache_size = 4Mmax_heap_table_size = 128Mread_rnd_buffer_size = 16Msort_buffer_size = 16Mjoin_buffer_size = 16Mthread_cache_size = 16query_cache_size = 128Mquery_cache_limit = 4Mft_min_word_len = 8thread_stack = 512Ktransaction_isolation = REPEATABLE-READtmp_table_size = 128M#log-bin=mysql-binlong_query_time = 6server_id=1innodb_buffer_pool_size = 1Ginnodb_thread_concurrency = 16innodb_log_buffer_size = 16Minnodb_log_file_size = 512Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = on[mysqldump]quickmax_allowed_packet = 32M[mysql]no-auto-rehashdefault-character-set=utf8safe-updates[myisamchk]key_buffer = 16Msort_buffer_size = 16Mread_buffer = 8Mwrite_buffer = 8M[mysqlhotcopy]interactive-timeout[mysqld_safe]open-files-limit = 8192[client]port=3306socket=/usr/local/mysql/data/mysql.sock#default-character-set=utf8
如果提示已存在文件是否覆盖时,覆盖即可。
然后执行数据库的初始化操作,
/usr/local/mysql/bin/mysqld --initialize --user=mysql,
这时候会初始化数据库并创建一个数据库 root 账号,但是要注意,这个账号是有默认密码的,初始化的时候屏幕上会输出初始化的密码,如果错过了,可以通过查看 /root/.mysql_secret 即可看到默认的密码。
执行 cp /usr/local/mysql/support-files/mysql.server /etc/init.d,将 mysql 的服务启动脚本复制过去,然后执行 service mysql.server start 启动 mysql。
最后 /usr/local/mysql/bin/mysql -rroot -p,输入密码回车,如果出现Access denied for user 'root'@'localhost' (using password: YES),一般情况下
service mysql.server restart 重新启动即可
通过之后,可以用以下命令重新设置root密码
set password=password('你的密码');
至此,基本的安装流程完毕
以下方法可以设置开机启动
命令echo "service mysqld start" >> /etc/rc.local
或者进入/etc/目录,直接vim rc.local编辑rc.local文件,在最后一行添加"service mysqld start",保存退出。
以上就是centos安装MySQL5.7.18的详细安装教程,内容较为全面,而且我也相信有相当的一些工具可能是我们日常工作可能会见到或用到的。通过这篇文章,希望你能收获更多。