Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql 必须创建 不然会报错
日志保存位置:/data/log/mysql 必须创建 不然会报错
安装必要组件:yum -y install gcc* libaio 重要
关闭防火墙 重要,不然外部没办法访问mysql
mysql 启动、重启命令:service mysql start 后面没有带d
mysql配置文件所在位置:/etc/my.cnf
mysql启动文件所在位置:/etc/init.d/mysql
2.下载mysql
选择社区版,然后选择 mysql 版本 选择 linux 通用版
可以直接使用 wget 下载
下载完成以后,解压到 /usr/local/ 目录下 将文件名修改为 mysql
3.创建 mysql 用户和mysql组
useradd mysql
groupadd mysql
4.改变mysql安装目录所有者
cd /usr/local/mysql
chown -R mysql . (注意后面还有个点) 改变目录所有
chgrp -R mysql . 改变目录所有组
5.配置参数
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
此处需要注意记录生成的临时密码,如上文:YLi>7ecpe;YP
bin/mysql_ssl_rsa_setup --datadir=/data/mysql
6.修改mysql配置文件和mysql启动文件
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf ( mysql 配置文件 )
cp mysql.server /etc/init.d/mysql ( mysql 启动脚本 )
vim /etc/init.d/mysql 修改mysql启动文件
vim /etc/my.cnf 修改mysql配置文件
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock
# character-set-server = utf8
[mysql]
no-auto-rehash
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
socket = /usr/local/mysql/mysql.sock
basedir = /usr/local/mysql
max_allowed_packet = 32M
datadir = /data/mysql
explicit_defaults_for_timestamp = true
skip-ssl
secure-file-priv = NULL
lower_case_table_names = 1
back_log = 300
max_connections = 3000
max_connect_errors = 100
table_open_cache = 4096
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
max_heap_table_size = 128M
###*** slow query parameters
long_query_time = 6
slow_query_log
slow_query_log_file = /data/log/mysql/slow.log
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
open-files-limit = 8192
log-error=/data/log/mysql/mysql_3306.err
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
7.启动mysql
cd /usr/local/mysql
bin/mysqld_safe --user=mysql & (启动mysql)
bin/mysql --user=root –p (输入第5步生成的临时密码)
此时会成功进入mysql
mysql> set password=password('root'); (将root帐户密码设为root)
mysql>grant all privileges on *.* to root@'%' identified by 'root'; (允许root执行所有命令)
mysql> flush privileges; (立刻生效)
8.将 mysql 命令 添加到环境变量
vim /etc/profile
添加:export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile ( 添加的环境变量立刻生效 )
9.开机启动mysql
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on