MySQL 5.7.21如何在Linux平台中安装Part 2
这篇文章主要介绍了MySQL 5.7.21如何在Linux平台中安装Part 2,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
1. 目录规划
目录名称 | 参数名称 | 路径地址 |
---|---|---|
安装目录 | basedir | /usr/local/mysql |
数据文件目录 | datadir | /data/mysql/data |
临时文件目录 | tmpdir | /data/mysql/tmp |
socket文件目录 | socket | /data/mysql/data/mysql.sock |
bin日志文件目录 | log_bin | /datalog/mysql/binlog |
relay日志文件目录 | relay_log | /datalog/mysql/relaylog |
2. MySQL 5.7 下载
目前MySQL 社区的GA 提供5 和8 的下载
由于目前大多数系统用的还是5的版本
这里统一使用5的版本
注意,下面是按照5.7.21的版本安装,5.25相同
MySQL Community Server 5.7.25
3. 新建用户及目录
/usr/sbin/groupadd -g 105 mysql
/usr/sbin/useradd -u 105 -g mysql mysql
echo "mysql123" |passwd mysql --stdin
4. 新建目录
mkdir -p /data/mysql/softwaremkdir -p /usr/local/mysqlmkdir -p /data/mysql/datamkdir -p /datalog/mysql/binlogmkdir -p /datalog/mysql/relaylogchown -R mysql:mysql /usr/local/mysqlmkdir -p /data/mysql/tmpchown -R mysql:mysql /data/mysqlchown -R mysql:mysql /datalog/mysql/
5. 配置环境变量
su - mysqlvim ~/.bash_profileexport MYSQL_HOME=/usr/local/mysqlexport PATH=$HOME/bin:$MYSQL_HOME/bin:$PATHexport LD_LIBRARY_PATH=$MYSQL_HOME/lib:$LD_LIBRARY_PATHsource ~/.bash_profile
6. 建立配置文件
我们这里建立 /etc/my.cnf
[mysql]user =password =[mysqld]#-----------------MySQL Basic Setting-----------------#server-id = 1723161113port = 3306user = mysqlpid-file = mysql.pidcharacter_set_server = utf8mb4default_storage_engine = InnoDBskip_name_resolve = 1lower_case_table_names = 1explicit_defaults_for_timestamp = 1open_files_limit = 65535max_connections = 1000max_connect_errors = 100000basedir = /usr/local/mysqldatadir = /data/mysql/datatmpdir = /data/mysql/tmpsocket = /data/mysql/data/mysql.sockquery_cache_type = query_cache_size = join_buffer_size = 64Mtmp_table_size = 64Mmax_allowed_packet = 32Mread_buffer_size = 16Mread_rnd_buffer_size = 32Msort_buffer_size = 32M#-----------------MySQL Log Setting-----------------#log_error = mysql-error.loglog_bin = /datalog/mysql/binlog/mysql-bin.logslow_query_log_file = mysql-slow.logrelay_log = /datalog/mysql/relaylog/mysql-relay.loglog_slave_updates = 1sync_binlog = 1relay_log_recovery = 1binlog_format = rowexpire_logs_days = 14slow_query_log = 1long_query_time = 2log_queries_not_using_indexes = 1log_throttle_queries_not_using_indexes = 10log_slow_admin_statements = 1log_slow_slave_statements = 1min_examined_row_limit = 1000#-----------------MySQL Replication Setting-----------------#slave_skip_errors = ddl_exist_errorsmaster_info_repository = TABLErelay_log_info_repository = TABLEgtid_mode = onenforce_gtid_consistency = 1binlog_rows_query_log_events = 1#-----------------MySQL InnoDB Setting-----------------#innodb_page_size = 16384innodb_buffer_pool_size = 25600Minnodb_data_file_path = ibdata1:1G:autoextendinnodb_buffer_pool_instances = 8innodb_file_per_table = 1innodb_buffer_pool_load_at_startup = 1innodb_buffer_pool_dump_at_shutdown = 1innodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 5innodb_io_capacity = 800innodb_io_capacity_max = 2000innodb_flush_method = O_DIRECTinnodb_file_format = Barracudainnodb_file_format_max = Barracudainnodb_undo_logs = 128innodb_undo_tablespaces = 3innodb_flush_neighbors = 1innodb_log_file_size = 2Ginnodb_log_buffer_size = 16777216innodb_print_all_deadlocks = 1innodb_strict_mode = 1innodb_sort_buffer_size = 67108864#-----------------MySQL semi Replication Setting-----------------##plugin_dir = /usr/local/mysql/lib/plugin#plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"#loose_rpl_semi_sync_master_enabled = 1#loose_rpl_semi_sync_slave_enabled = 1#loose_rpl_semi_sync_master_timeout = 5000
修改my.cnf权限
chown mysql:mysql /etc/my.cnf
7. 依赖包检查
libaio-0.3.107-10.el6.x86_64libaio-devel-0.3.107-10.el6.x86_64lvm2-2.02.143-7.el6_8.1.x86_64
8. 卸载以前版本
如果有以前版本的MySQL ,则需要先下载
如只有lib库则可以不用动
RedHat Enterprise Linux 6适用】
# rpm -qa|grep -i mysqlmysql-libs-5.1.71-1.el6.x86_64qt-mysql-4.6.2-26.el6_4.x86_64mysql-5.1.71-1.el6.x86_64mysql-server-5.1.71-1.el6.x86_64#yum remove mysql-5.1.71-1.el6.x86_64 qt-mysql-4.6.2-26.el6_4.x86_64 mysql-libs-5.1.71-1.el6.x86_64 mysql-server-5.1.71-1.el6.x86_64
【RedHat Enterprise Linux 7适用】
# rpm -qa|grep -i mariadb*mariadb-server-5.5.52-1.el7.x86_64mariadb-libs-5.5.52-1.el7.x86_64mariadb-embedded-5.5.52-1.el7.x86_64mariadb-test-5.5.52-1.el7.x86_64mariadb-bench-5.5.52-1.el7.x86_64mariadb-5.5.52-1.el7.x86_64mariadb-devel-5.5.52-1.el7.x86_64mariadb-embedded-devel-5.5.52-1.el7.x86_64# yum remove -y mariadb*
9. 解压文件
9.1 解压安装文件
su - mysqltar xzvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql/ --strip-components=1
9.2 配置服务文件
这里将mysql.server文件拷贝值init.d目录使其可以当作服务启停
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
这里修改下面几处
vim /etc/init.d/mysqldbasedir=/usr/local/mysqldatadir=/data/mysql/datalockdir='/data/mysql/data'mysqld_pid_file_path=/data/mysql/data/mysql.pid
10. 初始化数据库
接下来我们初始化MySQL
# su - mysql$cd /usr/local/mysql$/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
初始化过程中可以通过error文件查看进度
tail -f /data/mysql/data/mysql-error.log
11. 启动数据库
$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &$ netstat -lntp|grep mysqld
后续可以使用如下命令启停数据库
service mysqld stop
service mysqld start
service mysqld restart
设置MySQL自启动
chkconfig mysqld on
12. 连接数据库
默认密码在error文件中有
cat /data/mysql/data/mysql-error.log |grep password
使用如下命令连接
mysql -S /data/mysql/data/mysql.sock -uroot -ppassword
感谢你能够认真阅读完这篇文章,希望小编分享的"MySQL 5.7.21如何在Linux平台中安装Part 2"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!