1.首先要检查是否已经安装过MYSQL
ps -ef|grep mysqld 查看进程
rpm -qa |grep -i mysql 查看是否有安装包
这是在生产中防止重复安装的命令,-i参数的意义是忽略大小写
2.下载MYSQL的安装包
3.将安装包解压
使用tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
4.创建用户和用户组
使用groupadd -g 101 dba
和useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin 用来添加用来管理MYSQL的用户和用户组
使用useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin 后切换到mysqladmin用户如果出现“-bash-4.1$”说明环境变量没有配置好,具体的解决办法请参照https://blog.csdn.net/qq_43116788/article/details/82934884里面有详细的解决办法
5.Create /etc/my.cnf(640) 修改配置文件
打开配置文件并且编辑
使用dG命令清空原始的配置文件,并把我们准备好的配置文件内容粘贴上去
[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 32M
max_allowed_packet = 16M
myisam_sort_buffer_size=128M
tmp_table_size=32M
table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600
Try number of CPU’s*2 for thread_concurrency
thread_concurrency = 32
#isolation level and default engine
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED
server-id = 1
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/hostname.pid
#open performance schema
log-warnings
sysdate-is-now
binlog_format = MIXED
log_bin_trust_function_creators=1
log-error = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err
#for replication slave
#log-slave-updates
#sync_binlog = 1
#for innodb options
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:500M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M
innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 50M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 100
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_locks_unsafe_for_binlog=1
#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=4
innodb-write-io-threads=4
innodb-io-capacity=200
#purge threads change default(0) to 1 for purge
innodb_purge_threads=1
innodb_use_native_aio=on
#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names=1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
注意粘贴后容易丢失首行的部分字母,请重点核对
粘贴完成后保存并退出编辑
6.修改权限
因为我们第一次安装是用的root权限但是在生产中是不可能人人都用root权限的所以在此我们配置一下以方便其他用户或者是用户组使用
赋予权限640!
更改文件所有者
切换mysqladmin用户到/usr/mysql/路径下建立arch文件夹,用于归档
mkdir arch
在这里我们顺带安装一个RPM包以免尝试安装时报错(在此需要我们切换到root权限才能完成安装)
7.再次安装
输入scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 命令进行再次安装操作
8.配置mySQL服务器的自动启动功能
将服务文件拷贝到init.d下,并重命名为mysql
赋予可执行权限
删除已有的mysql服务
添加服务并设置自动启动
编辑配置文件添加一句
su - mysqladmin -c “/etc/init.d/mysql start --federated”
9.启动mysql并查看进程
切换到mysql用户
删除系统自己生成的家目录,因为我们已经在etc文件下配置过my.cnf文件下了,所以这个文件变成了多余的
配置mysql的环境变量
重新进入mysql用户并查看环境变量是否生效、
启动mysql,使用mysqld_safe &
[1] 5237命令