Linux-centos-7.2-64bit 安装配置mysql

2018-04-12

安装在/usr/local/下,配置文件在/etc/my.ini

1.下载mysql安装包到 /usr/local/software

cd /usr/local/software

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

2.安装依赖环境

yum -y install perl perl-devel autoconf libaio
yum install -y perl-Data-Dumper

3.解压安装包

tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

4.复制安装包至 /usr/local 下 并修改文件夹名为 mysql

cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r

5.添加系统mysql组和mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql

6.进入 /usr/local/mysql 修改目录拥有者为mysql用户
cd mysql/
chown -R mysql:mysql ./

7.进行安装
./scripts/mysql_install_db --user=mysql

8.修改当前目录拥有者为root用户
chown -R root:root ./

9.修改当前data目录拥有者为mysql用户
chown -R mysql:mysql data

10.添加mysql服务开机自启动
cp support-files/mysql.server /etc/init.d/mysql

# 赋予可执行权限
# 添加服务
# 显示服务列表
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list

11.启动mysql服务

#创建缺少的文件夹
mkdir /var/log/mariadb
service mysql start

12.添加软连接
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/local/bin/mysqldump

13.解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

建立一个软连接:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

14.配置my.ini 打开/etc/my.cnf
在[mysqld]后面任意一行添加“skip-grant-tables”在[mysqld]上面加入下面两句话

[client]
default-character-set=utf8
在[mysqld]最下面加入下面几句话
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

skip-grant-tables #用来跳过密码验证的过程

15.保存 /etc/my.cnf 并重启mysql 服务器

service mysql restart

16.修改root登录密码

mysql
use mysql;
update user set password=password("新密码") where user="root";
flush privileges;

17.删除匿名用户,使用root用户登陆数据库

delete from mysql.user where User='';
flush privileges;

18.修改其他客户端连接数据库权限
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;

flush privileges;

19.阿里云服务器开启3306端口,外部才能连接3306

网络和安全-安全组-配置规则-添加安全规则

上一篇:【CSS学习笔记】a标签的四种伪类


下一篇:SqlServer查询表名的备注(查询表名描述 MS_Description)