安装
1、查看系统是否安装了MySQL
使用命令:#rpm -qa | grep mysql
2、卸载已安装的MySQL
卸载mysql命令如下:
#rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
要将 /var/lib/mysql文件夹下的所有文件都删除干净-
3、下载安装包下载地址
这里以centos 6.8 为例。下载Bundle包。然后解压:
-
3、安装新的MySQL
命令如下:
#rpm -ivh MySQL-server-5.6.30-1.el6.x86_64.rpm
#rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm
#rpm -ivh MySQL-devel-5.6.30-1.el6.x86_64.rpm
-
4、启动MySQL服务
#service mysql start
查看MySQL运行状态的方法:
使用命令:# /etc/rc.d/init.d/mysql status
结果: 显示 “SUCCESS” 则已经运行
显示 “FAILED” 则没有运行MySQL服务一些其他命令- a、察看mysql是否在自动启动列表: # /sbin/chkconfig –list
- b、添加mysql到系统自启动服务组: # /sbin/chkconfig – add mysql
- c、把mysql从启动服务组中删除: # /sbin/chkconfig – del mysql
- d、停止mysql服务: # service mysql stop
- e、脚本启动mysql服务: # /etc/rc.d/init.d/mysqld start
- f、脚本停止mysql服务: # /etc/rc.d/init.d/mysqld stop*
5、安装完成之后为MySQL设置root密码。** 命令如下:-
# mysql -u root -p
会提示输入密码,初始root密码保存在'/root/.mysql_secret'文件中
接着输入
mysql>SET PASSWORD = PASSWORD('123456');
安装目录说明
- /var/lib/mysql 数据库文件
- /usr/share/mysql 命令及配置文件
- /usr/bin(mysqladmin、mysqldump等命令)
配置文件
- 1、拷贝 /usr/share/mysql/my-huge.cnf 到 /etc/my.cnf(如果已有该文件可以直接修改) 命令如下:# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
- 2、修改my.cnf 文件 在 [mysqld]下增加 lower_case_table_names=1 #表名全部为小写,避免出现大小写敏感
- 3、重启mysql
为连接MySQL的主机分配权限:
命令如下:
>mysql GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO root@xxx.xxx.x.xx identified by '123456';
xxx.xxx.x.xx是你的IP
开机启动MySQL
用root用户登录终端
查看是否已经有MySQL的服务
#chkconfig --list
如果没有MySQL(如果有请忽略这个步骤)
#chkconfig --add mysql
设置开机启动mysql服务
#chkconfig mysql on
MySQL默认字符集
更改MySQL默认字符集 查看mysql字符集:
mysql> show variables like 'character_set_%';
修改物理文件位置
- 将/var/lib/mysql 拷贝到指定的目录下,这里放到/home/data/mysql下
- 修改文件夹的组
chown -R mysql:mysql mysql
- 修改配置文件,设置目录的地方。文章末尾的示例中有体现
- 重启mysql。
如果重启报错
Starting MySQL...The server quit without updating PID file (/usr/local/mysql/data/rekfan.pid).
。可能是selinux惹的祸,如果是centos系统,默认会开启selinux解决方法:
关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。
示例配置文件
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysql]
socket = /home/data/mysql/mysql.sock
[mysqld]
port= 3306
socket = /home/data/mysql/mysql.sock
datadir = /home/data/mysql
# 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 = .....
# 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
join_buffer_size = 256M
sort_buffer_size = 128M
read_rnd_buffer_size = 128M
lower_case_table_names=1
tmp_table_size = 256M
max_connections = 1000
max_connect_errors = 10000000
wait_timeout = 1000000
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /home/data/mysql/mysql.sock