linux mysql-5.7.22 完整安装步骤(包含各种网上安装的意外处理,本人亲测可行)

操作系统环境:ubuntu 16
mysql版本:5.7.22
安装文件准备:mysql-5.7.22-linux-glibc2.12-x86_64.tar(官网可下)
系统用户:以下 xielinjun 为本人的个人帐号,后期操作将全部在 root 帐号下进行.所以请注意帐号的切换
路径准备:
1.创建mysql安装包文件放置目录
xielinjun@ubuntu:~$ mkdir soft
xielinjun@ubuntu:~$ cd soft/
2.将文件 mysql-5.7.22-linux-glibc2.12-x86_64.tar 复制到上面创建的 soft 目录中




安装流程:


1.解压 mysql-5.7.22-linux-glibc2.12-x86_64.tar 文件,解压完成之后将会得到 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 和 mysql-test-5.7.22-linux-glibc2.12-x86_64.tar.gz 这两个文件
xielinjun@ubuntu:~/soft$ tar -xf mysql-5.7.22-linux-glibc2.12-x86_64.tar


2.切换 root 帐号.(如果当前帐号已经为 root 忽略此步)
xielinjun@ubuntu:~/soft$ su


3.继续解压 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 文件.
root@ubuntu:/home/xielinjun/soft# tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz


4.重命名上面解压出来的文件夹的名字.
root@ubuntu:/home/xielinjun/soft# mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql


5.创建 mysql 的用户组和用户名.
root@ubuntu:/home/xielinjun/soft# useradd mysql
root@ubuntu:/home/xielinjun/soft# useradd -r -g mysql mysql


6.将 mysql 目录的权限赋给上面刚建立的 mysql 用户和用户组
root@ubuntu:/home/xielinjun/soft# chown mysql:mysql -R mysql


7.进入 mysql 的 bin 目录并初始化 mysql
root@ubuntu:/home/xielinjun/soft# cd mysql/bin/
root@ubuntu:/home/xielinjun/soft/mysql/bin# ./mysqld --initialize --user=mysql --basedir=/home/xielinjun/soft/mysql --datadir=/home/xielinjun/soft/mysql/data

执行以上命令,如果得到以下错误:
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

那么就需要先执行以下命令:
root@ubuntu:/home/xielinjun/soft/mysql/bin# sudo apt-get install libaio-dev

再重复执行:
root@ubuntu:/home/xielinjun/soft/mysql/bin# ./mysqld --initialize --user=mysql --basedir=/home/xielinjun/soft/mysql --datadir=/home/xielinjun/soft/mysql/data


以上命令都执行完成之后,会得到类似如下结果:
root@ubuntu:/home/xielinjun/soft/mysql/bin# ./mysqld --initialize --user=mysql --basedir=/home/xielinjun/soft/mysql --datadir=/home/xielinjun/soft/mysql/data
2018-07-06T14:07:55.399661Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-06T14:07:59.903295Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-07-06T14:08:02.374222Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-07-06T14:08:02.449272Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: fedd5a45-8125-11e8-b9fc-000c293c649f.
2018-07-06T14:08:02.456237Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-07-06T14:08:02.460133Z 1 [Note] A temporary password is generated for root@localhost: yvSeY9#pznGT
其中最后一行的最后一个 : (冒号) 往后是 mysql 数据库初始化生成的 root 帐号的默认密码,后面会使用.


8.生成 ssl 证书.(本人亲测可以忽略此步骤)
root@ubuntu:/home/xielinjun/soft/mysql/bin# ./mysql_ssl_rsa_setup --datadir=/home/xielinjun/soft/mysql/data/



9.手动创建 my.cnf 文件,并录入基本内容.
root@ubuntu:/home/xielinjun/soft/mysql/bin# vi /etc/my.cnf

将以下内容复制粘贴进 my.cnf 文件(该文件其他内容自行百度随意添加):
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/home/xielinjun/soft/mysql
datadir=/home/xielinjun/soft/mysql/data
socket=/tmp/mysql.sock
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid

lower_case_table_names = 1

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

max_connections=5000

default-time_zone = '+8:00'


保存并退出文件:
:qw


10.将 mysql.server 文件复制到 /etc/init.d/mysql
root@ubuntu:/home/xielinjun/soft/mysql/bin# cd ..
root@ubuntu:/home/xielinjun/soft/mysql# cd support-files/
root@ubuntu:/home/xielinjun/soft/mysql/support-files# cp mysql.server /etc/init.d/mysql


11.修改 /etc/init.d/mysql 文件的内容.
root@ubuntu:/home/xielinjun/soft/mysql/support-files# vi /etc/init.d/mysql

找到并修改以下两行内容:
basedir=/home/xielinjun/soft/mysql
datadir=/home/xielinjun/soft/mysql/dat


保存并退出文件:
:qw


12.启动 mysql 服务.
root@ubuntu:/home/xielinjun/soft/mysql/support-files# /etc/init.d/mysql start

执行以上命令,如果得到以下错误:
[....] Starting mysql (via systemctl): mysql.serviceFailed to start mysql.service: Unit mysql.service not found. failed!

那么需要执行以下指令:
root@ubuntu:/home/xielinjun/soft/mysql/support-files# systemctl enable mysql.service

再重复执行:
root@ubuntu:/home/xielinjun/soft/mysql/support-files# /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.





测试并修改密码(接着上面操作):


1.链接本地 mysql.(注意 root 的登录密码就是 上面第7步最后的描述)
root@ubuntu:/home/xielinjun/soft/mysql/support-files# cd ..
root@ubuntu:/home/xielinjun/soft/mysql# cd bin/
root@ubuntu:/home/xielinjun/soft/mysql/bin# ./mysql -uroot -pyvSeY9#pznGT


2.修改默认登录密码.(****** 就是您的密码,自行修改即可)
mysql> SET PASSWORD FOR 'root'@localhost=PASSWORD('******');
Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

grant all privileges on *.* to '用户名'@'IP地址' identified by '密码';

update mysql.user set host='修改后的IP' where user='要修改的账号';

你可能感兴趣的:(linux mysql-5.7.22 完整安装步骤(包含各种网上安装的意外处理,本人亲测可行))