centos7安装mysql

一、下载

地址:https://dev.mysql.com/downloads/mysql/

版本:

或者在linux中下载:

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

 

二、安装

安装libaio和numactl

yum install libaio
yum install numactl

解压并复制

tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mkdir -p /usr/local/mysql
mkdir -p /usr/local/mysql/data
mv mysql-5.7.21-linux-glibc2.12-x86_64/* /usr/local/mysql/ 

创建mysql用户并修改权限

groupadd mysql
useradd -r -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/ 

初始化数据,需要记住最后一段登录密码

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

修改my.cnf

vi /etc/my.cnf
max_allowed_packet = 20M
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock

增加软链接

cd /usr/local/bin
ln -fs /usr/local/mysql/bin/mysql mysql
ln -fs /usr/local/mysql/bin/mysqld mysqld
ln -s /usr/local/mysql/data/mysql.sock /tmp

 

三、启动

启动

/usr/local/mysql/bin/mysqld --user=root

登录、输入密码

mysql -u root -p

修改密码(mysql5)

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('数据库密码');

修改密码(mysql8)

alter user user() IDENTIFIED by '数据库密码';

允许远程登录

use mysql;
update user set host = '%' where user = 'root';

增加root访问权限(mysql5)

grant all privileges on *.* to root@'%' identified by '******'; //***表示数据库连接密码
flush privileges;

 修改密码加密方式(mysql8,如果navicat低于12.1.12)

alter user 'root'@'localhost' identified with mysql_native_password by '数据库密码';
flush privileges;

 

四、Navicat连接阿里云

如果没有增加root访问权限,就需要:Navicat升级到11.2以上,新建连接,在常规里填写信息,其中主机名localhost,在SSH里填写信息,保存连接

如果已经增加,就只要在常规里填写信息,连接

 

posted @ 2018-03-19 11:01  syxsdhy  阅读(657)  评论(0编辑  收藏  举报