本文基本按照https://www.cnblogs.com/shizhongyang/p/8464876.html,只不过有些路径改成自己的了。为了日后方便部署,重新整理发一下作为记录。
linux环境:
[root@iZbp1bh80q4p151cuejcqsZ ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core
mysql版本
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz:
先查看哪个目录磁盘空间较多
df -h /*
作者选择 /home 目录
步骤:
cd /opt
mkdir soft #mysql安装包存放位置
#mysql上传到 /root/soft目录
mkdir -p /home/data/mysql #选择home的理由上面已经阐述
cd soft
tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz #解压缩
mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql #改名字
groupadd mysql #创建mysql用户组
useradd -r -g mysql mysql #创建mysql用户
#关联myql用户到mysql用户组中
chown -R mysql:mysql /opt/soft/mysql/
chown -R mysql:mysql /home/data/mysql/
chown -R mysql /opt/soft/mysql/
chown -R mysql /home/data/mysql
chmod -R 755 /opt/soft/mysql/
cd /opt/soft/mysql/bin
重要!!重要!!重要!! 记住下面的临时密码
./mysqld --user=mysql --basedir=/opt/soft/mysql --datadir=/home/data/mysql --initialize
#临时密码 2019-06-03T12:17:13.441571Z 1 [Note] A temporary password is generated for root@localhost: <y#F:qXiX0NC
修改mysql配置文件
vi /opt/soft/mysql/support-files/mysql.server
basedir=
datadir=
->
basedir=/opt/soft/mysql
datadir=/home/data/mysql
最后的修改:
cp /opt/soft/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vi /etc/my.cnf 修改为:
[client]
no-beep
socket =/opt/soft/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/opt/soft/mysql
datadir=/home/data/mysql
port=3306
pid-file=/opt/soft/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /opt/soft/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /home/data/mysql
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 604800 #7*24小时
wait_timeout = 604800 #7*24小时
log-bin-trust-function-creators=1
event_scheduler=1 #开启定时任务
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
启动mysql
/etc/init.d/mysqld start
注意:如果出现以下报错就创建目录 mkdir /etc/my.cnf.d/
my_print_defaults: Can't read dir of '/etc/my.cnf.d' (Errcode: 2 - No such file or directory)
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Starting MySQL.my_print_defaults: Can't read dir of '/etc/my.cnf.d' (Errcode: 2 - No such file or directory)
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
my_print_defaults: Can't read dir of '/etc/my.cnf.d' (Errcode: 2 - No such file or directory)
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Logging to '/home/data/mysql/DB.err'.
The server quit without updating PID file (/home/data/mysql[FAILED].
添加mysql目录
vi ~/.bash_profile
增加一行:
PATH=$PATH:/opt/soft/mysql/bin
保存关闭
source ~/.bash_profile
进入mysql
mysql -u root -p
<y#F:qXiX0NC #上面步骤的临时密码
修改mysql密码
set password=password('root'); #这里设置root为新密码
flush privileges;
添加远程访问
show databases; #查看当前的数据库
use mysql;#使用mysql数据库
show tables;#查看当前的数据表
select * from user;#查看当前用户
#注意下面的 password('root') 改成自己想使用的密码
#当然我们可以不用下面这么长的文字创建新用户,不过为了了解一下MySql给每个user配置的privilege。
insert into user(Host, User, authentication_string, ssl_cipher, x509_issuer, x509_subject,
Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv,
Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv,
Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv,
Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Create_user_priv,
Event_priv, Trigger_priv, Create_tablespace_priv) value ('%', 'root', password('root'), '', '',
'', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y',
'Y', 'Y', 'Y');
flush privileges;
vi vi /etc/rc.d/rc.local
增加mysql重启
机器重启或者断电情况导致表需要修复的时候:
Table is marked as crashed and should be repaired 解决办法
1、首先进入mysql命令台:mysql -u root -p 回车 输入密码
2、查询所有的库:mysql> show databases;
3、进入数据库“eduyun_2015_sp1”是库名:mysql> use eduyun_2015_sp1;
4、check table newabout(newabout--出现错误的表)用来检查出现问题的表的状态,出现错误就正常
5、然后用repair table newabout
6、再用check table newabout 检查一下就ok了
顺便记录一下redis的安装
上传安装包安装:
tar -zxvf redis-5.0.3.tar.gz #解压缩
cd redis-5.0.3/
make
make install
启动:
./src/redis-server ./redis.conf
配置文件参见redis.conf里面详细内容