centos7安装 mysql-8.0.16

环境

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

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
Centos7安装mysql-connector-c++的步骤如下: 1. 首先,你需要下载mysql-connector-c++的安装包。你可以从MySQL官方网站上下载最新版本的mysql-connector-c++。 2. 下载完成后,解压安装包。你可以使用以下命令解压: ``` tar -zxvf mysql-connector-c++-<version>.tar.gz ``` 3. 进入解压后的目录: ``` cd mysql-connector-c++-<version> ``` 4. 接下来,你需要安装必要的依赖项。你可以使用以下命令安装: ``` sudo yum install mysql-connector-c++-devel ``` 5. 安装完成后,你可以开始编译和安装mysql-connector-c++。你可以使用以下命令: ``` ./configure make sudo make install ``` 6. 编译和安装完成后,你可以在你的代码中引入mysql-connector-c++的头文件,并使用相应的命名空间。例如: ``` #include <jdbc/mysql_connection.h> #include <jdbc/cppconn/driver.h> #include <jdbc/cppconn/exception.h> #include <jdbc/cppconn/resultset.h> #include <jdbc/cppconn/statement.h> #include <jdbc/cppconn/prepared_statement.h> ``` 7. 现在,你可以在你的代码中使用mysql-connector-c++来连接和操作MySQL数据库了。你可以参考mysql-connector-c++的官方文档和示例代码来学习如何使用它。 请注意,以上步骤仅适用于Centos7系统。如果你使用的是其他操作系统,请参考相应的文档来进行安装。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [Centos7 安装测试MySQL Connector/C++](https://blog.csdn.net/xqs51163/article/details/123690731)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Linux CentOS 7 安装mysql的两种方式](https://blog.csdn.net/Escorts/article/details/118941623)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值