1、首先关闭linux防火墙,执行命令
Centos 6 :chkconfig iptables off
?
Centos 7 : chkconfig firewalld off
2、官网下载合适的mysql版本
https://dev.mysql.com/downloads/mysql/5.6.html#downloads
3、解压文件
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
4、把解压文件移动指定文件夹内
mv mysql-5.6.33-linux-glibc2.5-x86_64/* /opt/mysql
groupadd mysql
?
useradd -r -g mysql mysql
错误信息 FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper 解决方法是安装autoconf库 执行命令:yum -y install autoconf
cp support-files/my-medium.cnf /etc/my.cnf
或:
cp support-files/my-default.cnf /etc/my.cnf
是否覆盖?按y 回车
vi /etc/my.cnf
在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 = /opt/mysql
datadir = /opt/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /opt/mysql/data/error.log
pid-file = /opt/mysql/data/mysql.pid
?
# 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
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
./mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/opt/mysql/data --basedir=/opt/mysql --pid-file=/opt/mysql/data/mysql.pid --tmpdir=/tmp
./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &
注意,如果光标停留在屏幕上,表示启动成功,需要我们先关闭shell终端,再开启一个新的shell终端,不要执行退出操作。如果出现 mysql
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /opt/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
?
chmod 700 /etc/init.d/mysql
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chown mysql:mysql -R /opt/mysql/
重启linux
reboot
查看mysql状态
service mysqld status
(1)、添加MySQL命令
ln -s /opt/mysql/bin/mysql /usr/bin (mysql的安装路径)
(2)、更改访问权限
登录mysql,执行下面命令
mysql -uroot -p
密码为空直接回车,运行以下两条命令
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ with grant option;
Flush privileges;
退出mysql
exit
重启linux,就完成了
reboot
原文:https://www.cnblogs.com/mengshuo/p/10815751.html