本篇内容介绍了“如何安装MySQL二进制包”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
本文使用二进制包安装及简单配置MySQL-v5.6.51版本。
5.6版本下载:
https://downloads.mysql.com/archives/community/
在此URL地址页面中的“Product Version”选择5.6的相应版本。
本文中使用本地VM虚机部署测试。
OS:CentOS Linux release 7.8.2003 (Core) 3.10.0-1160.15.2.el7.x86_64
虚机配置:2核CPU、4G内存
## 查询已安装的mariadb
rpm -qa |grep mariadb
## 卸载mariadb软件包,文件名为上述命令查询出来的文件
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
## 创建数据保存目录 mkdir -p /data/mysql ## 创建用户组mysql groupadd -r mysql ## 创建用户mysql并设置不能登录系统,指定宿主目录 useradd -g mysql -r -s /sbin/nologin -M -d /data/mysql mysql ## 修改数据保存目录属性及权限 chown mysql.mysql /data/mysql chmod 0700 /data/mysql
cd /data/tools wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ cd /usr/local ## 创建软链接,方便后续操作 ln -sv mysql-5.6.51-linux-glibc2.12-x86_64 mysql
vi /etc/my.cnf //输入以下内容 [client] port = 3306 socket = /usr/local/mysql/mysql.sock default-character-set = utf8mb4 [mysqld] port = 3306 socket = /usr/local/mysql/mysql.sock basedir = /usr/local/mysql datadir = /data/mysql character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect = 'SET NAMES utf8mb4' server-id = 1 log-slave-updates = true skip-external-locking skip-name-resolve key_buffer_size = 256M max_allowed_packet = 64M table_open_cache = 256 sort_buffer_size = 16M read_buffer_size = 8M read_rnd_buffer_size = 64M myisam_sort_buffer_size = 256M thread_cache_size = 16 query_cache_size = 128M query_cache_type = 1 log-bin = mysql-bin binlog_format = row expire_logs_days = 30 slow_query_log = on long_query_time = 2 slow_query_log_file = /data/mysql/db-slow.log gtid-mode = on enforce-gtid-consistency = true default-storage-engine = INNODB innodb_additional_mem_pool_size = 64M innodb_buffer_pool_size = 1G innodb_data_file_path = ibdata1:10M:autoextend innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 8 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 16M innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 60 innodb_file_per_table = on max_connections = 5000 interactive_timeout = 28800 wait_timeout = 28800 sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp = true [mysqldump] quick max_allowed_packet = 32M [mysql] no-auto-rehash default-character-set = utf8mb4 [myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] log-error = /data/mysql/mysql_err.log pid-file = /data/mysql/mysqld.pid
注:参数可根据实际环境需求进行修改,此处配置仅供参考。
cd /usr/local/mysql chown -R mysql.mysql .
cd /usr/local/mysql scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
注:5.6版本使用mysql_install_db命令初始化数据,针对root@localhost用户不设置临时密码,客户端可以直接通过mysql命令登录数据库系统。
cd /usr/local/mysql ## 帮助文件 echo "MANPATH /usr/local/mysql/man" >> /etc/man.config ## 头文件 ln -sv /usr/local/mysql/include /usr/include/mysql ## lib库 echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf ## 加载动态库文件 ldconfig
echo '######MySQL' >> /etc/profile echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile
cd /usr/local/mysql cp support-files/mysql.server /etc/rc.d/init.d/mysqld
/etc/init.d/mysqld start /usr/local/mysql/bin/mysql --version && echo -e "\e[31m mysql install is OK\e[0m"
echo -e "delete from mysql.user where user='';" | mysql -uroot -p //提示输入密码,直接Enter键确认 echo -e "delete from mysql.user where host='::1';" | mysql -uroot -p echo -e "drop database test;" | mysql -uroot -p
mysql -uroot -p //因初始化数据时没有设置密码,可以按两次确认键进入数据库 mysql> use mysql; mysql> update user set password = PASSWORD('123456') where user = 'root'; mysql> FLUSH PRIVILEGES;
# mysql -uroot -p //输入上述步骤中设置的密码登录数据库 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES;
启动:/etc/init.d/mysqld start
关闭:/etc/init.d/mysqld stop
重启:/etc/init.d/mysqld restart
查看状态:/etc/init.d/mysqld status
配置开机启动:echo "/etc/init.d/mysqld start" >> /etc/rc.local
“如何安装MySQL二进制包”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。