不知道大家之前对类似使用二进制演示MySQL安装步骤的文章有无了解,今天我在这里给大家再简单的讲讲。感兴趣的话就一起来看看正文部分吧,相信看完使用二进制演示MySQL安装步骤你一定会有所收获的。
安装环境准备:
系统版本:
[root@node2 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
selinux关闭:
[root@node2 ~]# getenforce
Disabled
防火墙关闭:
[root@node2 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
1、安装依赖包
yum install libaio -y
2、下载MySQL二进制安装包
https://dev.mysql.com (社区网站)
https://dev.mysql.com/downloads/file/?id=474755 (下载页面)
下载地址:
wget -p /opt/ https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
参数说明:-p 下载所有为了html页面显示正常的文件。
-p . /local 保存所有文件和目录到本地指定目录。
3、创建用户
useradd -s /sbin/nologin -M mysql
4、解压、创建目录、并创建软连接
mkdir /opt/mysql/
tar zxf /opt/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql/
cd /usr/local/
ln -s /opt/mysql/mysql-5.7.21-linux-glibc2.12-x86_64
5、创建数据库相关目录(备份用)
mkdir -pv /data/mysql/mysql3306/{data,logs,tmp}
6、更改相关目录的属性
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data
7、创建配置相关文件
配置文件为:/etc/my.cnf
cat > /etc/my.cnf << EOF
#my.cnf
[client]
port = 3306
socket = /tmp/mysql3306.sock
[mysql]
prompt="\u@\h [\d]>"
no-auto-rehash
[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
tmpdir = /data/mysql/mysql3306/tmp
port = 3306
socket = /tmp/mysql3306.sock
event_scheduler = 0
#timeout
interactive_timeout = 300
wait_timeout = 300
#character set
character-set-server = utf8
open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
lower_case_table_names =1
gtid-mode = on
enforce-gtid-consistency=1
#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000 # 1 second
#rpl_semi_sync_slave_enabled=1
####### slow log ######
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
####### binlog ######
binlog_format = row
server-id = 1003306
log-bin = /data/mysql/mysql3306/logs/mysql-bin
max_binlog_size = 256M
sync_binlog = 0
expire_logs_days = 10
#procedure
log_bin_trust_function_creators=1
####### relay log ######
skip_slave_start = 1
max_relay_log_size = 128M
relay_log_purge = 1
relay_log_recovery = 1
relay-log=relay-bin
relay-log-index = relay-bin.index
log_slave_updates = ON
#slave-skip-errors=1032,1053,1062
#skip-grant-tables
####### buffers & cache ######
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 200
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
#innodb
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:100M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 100M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
EOF
8、初始化数据库
cd /usr/local/mysql/
./bin/mysqld --defaults-file=/etc/my.cnf --initialize
9、创建启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
Starting MySQL............ SUCCESS! (启动成功)
10、创建快速启动的环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
11、查看MySQL初始密码
grep "password" /data/mysql/mysql3306/data/error.log
2018-02-01T05:44:04.334666Z 1 [Note] A temporary password is generated for root@localhost: usXXw5x.zzfw(默认登录密码)
12、修改初始密码
初始密码为: q=usXXw5x.zzfw 每次初始化密码都不会相同;
登录数据库修改密码为:123456
mysql -uroot -p初始密码
mysql> alter user user() identified by '123456';
或者:
mysql> SET PASSWORD=PASSWORD('123456');
mysql> flush privileges;
说明:此处的密码更改为123456,建议密码复杂化。
或者使用下面的命令:
PASSWD=$(grep 'password is' /data/mysql/mysql3306/data/error.log | awk '{print $NF}')
mysql -uroot -p"$PASSWD" --connect-expired-password -e "alter user user() identified by '123456';"
至此,MySQL数据库的二进制安装完成,您将进入一个暂新的数据世界。
看完使用二进制演示MySQL安装步骤这篇文章,大家觉得怎么样?如果想要了解更多相关,可以继续关注我们的行业资讯板块。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。