之前在linux环境下用源码编译安装了mysql5.7.12的版本,后来还需要安装mysql5.7的版本,就想着用二进制文件的方式安装,毕竟二进制文件的安装方式方便简单,基本的配置都能实现,详细过程如下:
可以去官网下载:https://dev.mysql.com/downloads/mysql/
或者可以访问百度网盘:https://pan.baidu.com/s/1KbEkWcgwYAiajXxG1bA1FA
提取码:kma7
#创建mysql用户(此用户不需要登录权限)
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
mkdir /app
tar -xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /app/getui_mysql
ln -s /app/getui_mysql/mysql-5.7.26-linux-glibc2.12-x86_64 /app/getui_mysql/mysql
#设置环境变量
echo 'export PATH=/app/getui_mysql/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
#查看mysql的版本信息
mysql -V
配置完之后可以在msyql日初始化时直接用my.cnf文件进行日初始化比较方便
下面这个是我自己的my.cnf比较全面,可以参看,详细的解释请参考另一篇博客:
my.cnf详解
[client]
port = 3306
socket = /app/getui_mysql/mysql/mysql.sock
[mysql]
prompt="\\u@\\h [\\d]>"
no-auto-rehash
[mysqld]
basedir = /app/getui_mysql/mysql
datadir = /data/mysql/data
socket = /app/getui_mysql/mysql/mysql.sock
tmpdir = /app/getui_mysql/mysql/tmp
user = mysql
port = 3306
server-id = 2
character-set-server = utf8mb4
event_scheduler = 0
sql_mode=''
default-time-zone = SYSTEM
log_timestamps = SYSTEM
explicit_defaults_for_timestamp=true
group_concat_max_len=102400
interactive_timeout = 600
wait_timeout = 600
open_files_limit = 65535
max_connections = 10000
max_connect_errors = 1000000
lower_case_table_names =1
skip_name_resolve = 1
gtid-mode = on
enforce-gtid-consistency=1
lock_wait_timeout = 3600
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /app/getui_mysql/mysql/logs/slow.log
log-slow-slave-statements = 1
log_slow_admin_statements = 1
log_queries_not_using_indexes =1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log-error = /app/getui_mysql/mysql/logs/error.log
log_error_verbosity = 2
binlog_format = row
log-bin = /app/getui_mysql/mysql/logs/mysql-bin
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
sync_binlog = 0
log_bin_trust_function_creators=1
expire_logs_days = 10
secure_file_priv="/tmp"
skip_slave_start = 1
max_relay_log_size = 128M
relay_log_purge = 1
relay_log_recovery = 1
relay-log=/app/getui_mysql/mysql/logs/relay-bin
relay-log-index=/app/getui_mysql/mysql/logs/relay-bin.index
log_slave_updates
relay-log-purge = 1
query_cache_size = 0
query_cache_type = 0
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
max_heap_table_size = 96M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 200
thread_stack = 512K
tmp_table_size = 96M
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
thread_cache_size = 7518
back_log = 1024
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 5G
myisam_repair_threads = 1
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_dump_at_shutdown = 1
innodb_buffer_pool_load_at_startup = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
transaction_isolation = REPEATABLE-READ
innodb_flush_method = O_DIRECT
innodb_stats_on_metadata = 0
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
internal_tmp_disk_storage_engine = InnoDB
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
performance_schema = 1
performance_schema_instrument = '%=on'
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 1
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"
[mysqldump]
quick
max_allowed_packet = 32M
mkdir /app/mysql/logs/ -p
mkdir /app/mysql/tmp -p
mkdir /data/mysql/data -p
chown -R mysql:mysql /data
chown -R mysql:mysql /app/getui_mysql
/app/getui_mysql/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize
初始化没有信息输出,最后直接完成即可,该初始化之后会分配一个临时使用的密码保存在/app/mysql/logs/error.log里面
#/app/getui_mysql/mysql/bin/mysqld --initialize-insecure --datadir=/data/mysql/data/ --user=mysql --basedir=/app/getui_mysql/mysql/
该命令也可以初始化,不用使用my.cnf文件,且没有初始化是产生临时使用的密码
前台启动命令:
/app/getui_mysql/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql &
/app/getui_mysql/mysql/bin/mysqladmin -S /app/getui_mysqlmysql/mysql.sock -p'' shutdown
-p''后面是密码
关闭:
直接kill 也可,用下面的命令也可以
/app/getui_mysql/mysql/bin/mysqladmin -S /app/getui_mysql/mysql/mysql.sock -p'' shutdown
-p''后面是密码
初始化时系统给的密码是临时性的,进入mysql后需要修改密码
mysql -u root -p
输入系统产生的密码
执行下面的密令就行密码修改:
set password='123456';
delete from mysql.user where user<>'root' or host<>'localhost';
flush privileges;
至此mysql就可以正常使用了
有没有发现没有使用service mysqld start 命令来启动mysql数据库,这个命令是需要进行配置之后才能使用的,配置方法如下:
cp /app/getui_mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld #修改下面两行
basedir=/app/getui_mysql/mysql
datadir=/data/mysql/data
ln -s /etc/my.cnf /app/mysql/my.cnf
然后就可以使用service mysqld start/stop restart 命令来操作数据库了