linux mysql5.7.17安装教程

一、基本配置

系统:Ubuntu-18.04 64位

数据库:mysql-5.7.17 64位

二、安装步骤

1、新建tmp目录

mkdir tmp

2、进入tmp目录并下载压缩包

cd /tmp 

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

3、创建MySQL系统用户

sudo groupadd mysql

sudo useradd -r -g mysql -s /bin/false mysql

4、安装MySQL

将之前下载的mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz安装包解压到/usr/local目录,并将目录名称改为mysql。然后创建mysql-files目录,并设置权限。

解压:sudo tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

重命名:sudo mv /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64/ /usr/local/mysql/

        进入MySQL安装目录:cd /usr/local/mysql/

       创建mysql-files目录:sudo mkdir mysql-files

       赋予750权限:sudo chmod 750 mysql-files

       将当前目录的拥有者设置为mysql用户和mysql组:

sudo chown -R mysql .

sudo chgrp -R mysql .

5、初始化MySQL

执行初始化命令:sudo bin/mysqld --initialize --user=mysql

注意事项:mysql初始化工作依赖libaio包,如果没有安装就会出现这个错误 “bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory”

检查是否已安装: apt-cache search libaio

如果没有,则安装: sudo apt-get install libaio1

安装失败则切换源镜像,重新安装:vi /etc/apt/sources.list

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

:wq

更新:sudo apt-get update

           sudo apt-get upgrade

配置ssl加密相关:sudo bin/mysql_ssl_rsa_setup

修改权限:sudo chown -R root .

                         sudo chown -R mysql data mysql-files

6、启动MySQL服务

cd /usr/local/mysql/bin

mysqld

7、使用MySQL

MySQL安装目录赋予权限:sudo chmod -R 777 /usr/local/mysql

MySQL服务器启动后,使用以下命令登录MySQL:bin/mysql -u root –p

需要注意的就是这个地方的密码,是你执行"sudo bin/mysqld --initialize --user=mysql"命令时产生的一个随机密码。

8、修改密码

set password for root@localhost = password('123456');

9、配置环境变量

vim /etc/profile

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

source /etc/profile

你可能感兴趣的:(数据库)