centos7安装 mysql-8.0.16
日期: 2020-12-12 分类: 跨站数据测试 483次阅读
环境
CentOS Linux release 7.6.1810 (Core)
mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
解压
[root@hadoop-2 software]# tar -vxf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
重命名:改什么随意,可不改
[root@hadoop-2 software]# mv mysql-8.0.16-linux-glibc2.12-x86_64 mysql8.0
进入目录,新建data文件
[root@hadoop-2 software]# cd mysql8.0/
[root@hadoop-2 mysql8.0]# mkdir data
新建my.cnf文件,加入内容
[root@hadoop-2 mysql8.0]# vim my.cnf
文件内容
[mysqld]
port=3306
#user=mysql
socket=/tmp/mysql.sock
basedir=/opt/software/mysql8.0
datadir=/opt/software/mysql8.0/data
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
初始化数据库
[root@hadoop-2 mysql8.0]# ./bin/mysqld --initialize --user=mysql --basedir=/opt/software/mysql8.0/ --datadir=/opt/software/mysql8.0/data/
2020-12-11T15:16:39.682697Z 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-12-11T15:16:39.682766Z 0 [System] [MY-013169] [Server] /opt/software/mysql8.0/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 9281
2020-12-11T15:16:53.815049Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vapp_h_<s0R+
2020-12-11T15:16:56.389493Z 0 [System] [MY-013170] [Server] /opt/software/mysql8.0/bin/mysqld (mysqld 8.0.16) initializing of server has completed
特别注意:root@localhost: vapp_h_<s0R+
root@localhost:后面跟的是初始化密码
这边如果直接启动会报错,还有一个地方需要改的
[root@hadoop-2 etc]# vim /etc/init.d/mysql
需要把
basedir=
datadir=
--否则service mysql start 会报Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysql
[root@hadoop-1 mysql8.0]# service mysql start
/etc/init.d/mysql: line 239: my_print_defaults: command not found
/etc/init.d/mysql: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
两个补充完整
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/opt/software/mysql8.0
datadir=/opt/software/mysql8.0/data
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
启动mysql服务
[root@hadoop-1 mysql8.0]# service mysql start
Starting MySQL......... SUCCESS!
登录
[root@hadoop-2 mysql8.0]# bin/mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@hadoop-2 mysql8.0]# bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.16
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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.00 sec)
配置一下环境变量方便登录
[root@hadoop-2 mysql8.0]# vim /etc/profile
#加入
export MYSQL_HOME=/opt/software/mysql8.0
export PATH=$MYSQL_HOME/bin:$PATH
[root@hadoop-2 mysql8.0]# source /etc/profile
成功......
问题:
1、这边稍微注意一下本来my.cnf 填的是socket=/tmp/mysql/mysql.sock
但是登录的时候一直报,所以干脆就改了,否则的话还应该创建mysql文件夹并授权的
[root@hadoop-2 mysql8.0]# bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@hadoop-2 tmp]# mkdir mysql
[root@hadoop-2 tmp]# chmod -R 777 mysql/
2、查看读了什么地方的my.cnf,ps:有些时候可能会读的其他地方的my.cnf,导致里面的路径不正确
[root@hadoop-2 mysql8.0]# bin/mysqld --verbose --help|grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default
3、登录报错 Can't connect to local MySQL server through socket '/tmp/mysql.sock' 原因是没有启动mysql服务
[root@hadoop-2 ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
[root@hadoop-2 ~]# service mysql start
Starting MySQL SUCCESS!
可以设置开机自动启动mysql服务
[root@hadoop-1 init.d]# cp /opt/software/mysql8.0/support-files/mysql.server /etc/init.d/mysqld
[root@hadoop-1 init.d]# chmod +x /etc/init.d/mysqld
[root@hadoop-1 init.d]# chkconfig --add mysqld
[root@hadoop-1 init.d]# 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]'.
mysql 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
命令说明
赋予可执行权限:chmod +x /etc/init.d/mysqld
添加为服务: chkconfig --add mysqld
查看服务列表: chkconfig --list
看到3、4、5状态为开或者为 on 则表示成功。如果是 关或者 off 则执行一下:chkconfig --level 345 mysqld on
reboot 重启虚拟机
注意:路径要写对/etc/init.d/mysqld ,也有文章是/etc/rc.d/init.d/ 我上面的是亲测没问题
远程登录:
没有设置之前远程是无法登录的,设置一下就可以了
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
精华推荐