CentOS安装MySQL5.6

mac2024-11-02  44

 

1、下载

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

2、卸载老版本MySQL

find / -name mysql rm -rf xxx

3、解压程序包

将MySQL安装在/usr/lcoal/mysql

tar -zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql

4、添加MySQL用户、组

groupadd mysql useradd -r -g mysql mysql

5、建立数据库存在文件夹

比如 /hdd/data/mysql

并配置权限:

chown -R mysql:mysql /hdd/data/mysql chmod -R 777 /hdd/data/mysql

6、更改mysql 路径权限

cd /usr/local/mysql chown -R mysql:mysql ./

7、安装

cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql --datadir=/hdd/data/mysql --basedir=/usr/local/mysql

(注意:yum install autoconf libaio libaio-devel)

8、拷贝、配置文件

cp support-files/my-default.cnf /etc/my.cnf

我的配置:

[client] port=3306 socket=/hdd/data/mysql/mysql.sock default-character-set=utf8 [mysqld] port=3306 datadir=/hdd/data/mysql socket=/hdd/data/mysql/mysql.sock character-set-server=utf8 collation-server=utf8_general_ci lower_case_table_names=1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d [mysql.server] user=mysql basedir=/usr/local/mysql

9、更改密码

先启动数据库:

./support-files/mysql.server start

设置密码:

./bin/mysqladmin -u root -h localhost.localdomain password 'your_password'

然后可以登录:

./bin/mysql -h 127.0.0.1 -u root -p your_password

设置root 远程登录

mysql> use mysql; mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES;

10、设置环境变量

在~/.bash_profile中添加

export PATH=$PATH:/usr/local/mysql/bin

11、加入service系统服务

cp support-files/mysql.server /etc/init.d/mysql chkconfig --add mysql chkconfig mysql on service mysql restart service mysql status

 

最新回复(0)