本文只适用于通过 rpm 二进制的方式安装,使用源码安装的请自行百度。
1. 准备步骤
下载地址 :https://dev.mysql.com/downloads/mysql/5.6.html
只需要以下安装文件
MySQL-client*.rpm
MySQL-devel*.rpm
MySQL-server*.rpm
需要使用 root 的账号进行操作
2. 卸载
卸载包
找出所有已经安装的包
rpm -qa | grep -i mysql
移除上面命令列出来的包
rpm -e pagename --nodeps
参数 pagename 上面出现的包名
参数 --nodeps 表示不检查依赖进行删除
删除文件
查找 mysql 的文件
find / -name mysql
删除
rm -rf folderORFileNamw
3. 安装
安装软件
依次执行
rpm -ivh MySQL-devel*.rpm
rpm -ivh MySQL-client*.rpm
rpm -ivh MySQL-server*.rpm
此时安装完成后 mysql 已经自动启动。查看是否启动成功可以使用 lsof -i:3306
来查看。
配置 my.cnf
使用命令 find / -name my-default.cnf
找到此文件。
复制配置文件到 /etc/
目录下
cp thisFilePath/my-default.cnf /etc/my.cnf
编辑修改 my.cnf 文件,只需要修改以下配置
# mysql 安装的基础目录
basedir = /usr
# mysql 数据库文件目录(默认目录)
datadir = /var/lib/mysql
# 端口(可随意修改)
port = 3306
# 大小写忽略(用于表名、字段)
lower_case_table_names=1
附上我的 my.cnf 配置
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/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.
[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 = /usr
datadir = /var/lib/mysql
port = 3306
# server_id = .....
# socket = .....
# 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 = 16M
# read_rnd_buffer_size = 2M
lower_case_table_name = 1
thread_cache_size = 16
query_cache_size = 128M
max_connections = 3000
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
5. 备注
以下为mysql 安装后的目录说明
Directory | Contents of Directory |
---|---|
/usr/bin | Client programs and scripts |
/usr/sbin | The mysqld server |
/var/lib/mysql | Log files, databases |
/usr/share/info | Manual in Info format |
/usr/share/man | Unix manual pages |
/usr/include/mysql | Include (header) files |
/usr/lib/mysql | Libraries |
/usr/share/mysql | Miscellaneous support files, including error messages,character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench | Benchmarks |