linux安装mysql-8.0.18

一、准备

1)检查使用已安装mysql

[root@tyke ~]# rpm -qa|grep mysql

 2)查询所有msyql对应的文件夹

[root@tyke ~]# whereis mysql

二、下载安装

 1)下载安装包

[root@tyke mysql]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

2)解压安装包

[root@tyke mysql]# tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

3)将安装包移动到/usr/local/目录下,并重命名mysql

[root@tyke mysql]# mv mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql

4)在mysql目录下创建data目录,存放数据

[root@tyke mysql]# cd /usr/local/mysql/

[root@tyke mysql]# mkdir data

创建mysql用户组合mysql用户

[root@tyke mysql]# groupadd mysql
[root@tyke mysql]# useradd -g mysql mysql

5)改变mysql目录权限

[root@tyke mysql]# chown -R mysql.mysql /usr/local/mysql

6)初始化数据库

[root@tyke data]# /usr/local/mysql/bin/mysqld --user=mysql --lower-case-table-names=1 --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

遇到报错如下

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

原因:缺少libaio库文件。解决方法如下

[root@tyke mysql]# yum install libaio* -y

再次执行

[root@tyke mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2020-04-22T16:58:49.852507Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-22T16:58:49.852658Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 3180
2020-04-22T16:58:55.653794Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sgwfY0ef*7dH

7)配置mysql

在mysql/support-files创建文件my-default.cnf

[root@tyke mysql]# cd /usr/local/mysql/support-files/

[root@tyke support-files]# touch my-default.cnf

复制配置文件到/etc/my.cnf,输入y确认复制文件

[root@tyke support-files]# cp -a ./my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

编辑my.cnf

[root@tyke support-files]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

8)配置MySQL服务

[root@tyke mysql]# cd /usr/local/mysql/
[root@tyke mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
[root@tyke mysql]# chmod -x /etc/rc.d/init.d/mysqld 
[root@tyke mysql]# chkconfig --add mysqld

检查是否生效
[root@tyke mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

9)配置环境变量

编辑/etc/profile文件

[root@tyke mysql]# vi /etc/profile

在profile文件末端追加如下两行配置,保存退出

PATH=/data/mysql/bin:/data/mysql/lib:$PATH
export PATH

设置环境变量立即生效

[root@tyke mysql]# source /etc/profile

10)启动mysql服务

[root@tyke mysql]# /usr/local/mysql/support-files/mysql.server start

启动遇到报错

Starting MySQL.Logging to '/usr/local/mysql/data/tyke.err'.
..The server quit without updating PID file (/usr/local/mysql/data/tyke.pid).                                                          [FAILED]

顺着报错信息,查看/usr/local/mysql/data/tyke.err错误日志文件

[root@tyke mysql]# cd /usr/local/mysql/data/

[root@tyke data]# cat tyke.err 

2020-04-22T17:32:23.800799Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-04-22T17:32:23.800845Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-04-22T17:32:23.801000Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) starting as process 3492
2020-04-22T17:32:25.250860Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
2020-04-22T17:32:25.251243Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2020-04-22T17:32:25.251508Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-04-22T17:32:25.770293Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18)  MySQL Community Server - GPL.

追踪到这句具体报错信息

Different lower_case_table_names settings for server ('1') and data dictionary ('0')

原因是:若初始化和启动值不一样则会在错误日志中有这种错误日志。

解决办法

在mysql数据库初始化的时候指定不区分大小写,在数据库实例启动的时候也要指定不区分大小写。即数据库初始化时lower_case_table_names的值和数据库启动时的值需要一样。
 在实际开发生产的应用中多是不区分大小写的即lower-case-table-names=1。

操作步骤

 /usr/local/mysql/bin/mysqld --user=mysql --lower-case-table-names=1 --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

显示如下说明服务器安装成功

[root@tyke data]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/tyke.err'.
..                                                         [  OK  ]

11)登录mysql,修改密码(密码为步骤6生成的临时密码,初始化数据库时的临时密码)

[root@tyke ~]# mysql -u root -p

遇到错误如下
-bash: mysql: command not found

原因,是因为系统默认会查找/usr/bin下的命令,由于mysql没有在这个目录下,所以出现not found。因此需要做一个软连接到/usr/bin目录下

解决办法,执行命令

[root@tyke ~]# ln -s  /usr/local/mysql/bin/mysql  /usr/bin

重新执行,输入密码登录mysql

[root@tyke ~]# mysql -u root -p                           
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

执行修改密码命令

mysql> set password for root@localhost = 'lovejody';
Query OK, 0 rows affected (0.01 sec)

12)开放远程连接

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

退出mysql

mysql> quit;

13)设置开机启动

1、将服务文件拷贝到init.d下,并重命名为mysql
[root@tyke ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 

cp: overwrite ‘/etc/init.d/mysqld’? y

2、赋予可执行权限

[root@tyke ~]# chmod +x /etc/init.d/mysqld 

3、添加服务

[root@tyke ~]# chkconfig --add mysqld

4、显示服务列表
[root@tyke ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

aegis           0:off   1:off   2:on    3:on    4:on    5:on    6:off
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

三、使用navicat远程连接测试

成功了,哈哈哈!

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值