MySQL版本:mysql-5.7.29
linux版本:CentOS7
需求背景:安装部署远程控制的Hive
安装步骤
卸载Centos7自带的mariadb
查看已经安装的mariadb
[root@hadoop1 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
卸载mariadb-libs-5.5.68-1.el7.x86_64
[root@hadoop1 ~]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
再次查看是否安装mariadb
[root@hadoop1 ~]# rpm -qa|grep mariadb
安装MySQL
MySQL官方下载地址:
按需下载所需版本
MySQL :: Download MySQL Community Server
创建需要安装到的文件夹,按需设置路径
[root@hadoop1 ~]# mkdir /export/software/mysql5.7.29
使用Xftp等工具将安装包传输至文件夹
cd到此文件夹下
[root@hadoop1 ~]# cd /export/software/mysql5.7.29/
[root@hadoop1 mysql5.7.29]# ls
mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
解压
[root@hadoop1 mysql5.7.29]# tar xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
----------------------------------------------------------------------------------
mysql-community-embedded-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-test-5.7.29-1.el7.x86_64.rpm
mysql-community-embedded-5.7.29-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-5.7.29-1.el7.x86_64.rpm
mysql-community-client-5.7.29-1.el7.x86_64.rpm
mysql-community-server-5.7.29-1.el7.x86_64.rpm
mysql-community-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm
mysql-community-common-5.7.29-1.el7.x86_64.rpm
联网安装依赖
[root@hadoop1 mysql5.7.29]# yum -y install libaio
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.qlu.edu.cn
* extras: mirrors.qlu.edu.cn
* updates: mirrors.qlu.edu.cn
软件包 libaio-0.3.109-13.el7.x86_64 已安装并且是最新版本
无须任何处理
继续安装
[root@hadoop1 mysql5.7.29]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm mysql-community-libs-5.7.29-1.el7.x86_64.rpm mysql-community-client-5.7.29-1.el7.x86_64.rpm mysql-community-server-5.7.29-1.el7.x86_64.rpm
-----------------------------------------------------------------------------------------------------------------------
警告:mysql-community-common-5.7.29-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.29-1.e################################# [ 25%]
2:mysql-community-libs-5.7.29-1.el7################################# [ 50%]
3:mysql-community-client-5.7.29-1.e################################# [ 75%]
4:mysql-community-server-5.7.29-1.e################################# [100%]
MySQL初始化
初始化
[root@hadoop1 mysql5.7.29]# mysqld --initialize
更改所属组
[root@hadoop1 mysql5.7.29]# chown mysql:mysql /var/lib/mysql -R
启动MySQL服务
[root@hadoop1 mysql5.7.29]# systemctl start mysqld.service
初次启动后生成临时密码,存放于/var/log/mysqld.log
[root@hadoop1 mysql5.7.29]# cat /var/log/mysqld.log
2022-12-29T08:28:32.945871Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-29T08:28:33.879106Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-12-29T08:28:33.945839Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-12-29T08:28:34.005861Z 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: c88c499d-8752-11ed-ae7a-000c293f0be3.
2022-12-29T08:28:34.007233Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-12-29T08:28:34.527265Z 0 [Warning] CA certificate ca.pem is self signed.
2022-12-29T08:28:35.060793Z 1 [Note] A temporary password is generated for root@localhost: bE/gJI;_f7Is
2022-12-29T08:30:18.426495Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-29T08:30:18.436281Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.29) starting as process 3472 ...
2022-12-29T08:30:18.457324Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-12-29T08:30:18.457479Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-12-29T08:30:18.457490Z 0 [Note] InnoDB: Uses event mutexes
2022-12-29T08:30:18.457496Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-12-29T08:30:18.457501Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-12-29T08:30:18.457506Z 0 [Note] InnoDB: Using Linux native AIO
2022-12-29T08:30:18.459446Z 0 [Note] InnoDB: Number of pools: 1
2022-12-29T08:30:18.460537Z 0 [Note] InnoDB: Using CPU crc32 instructions
2022-12-29T08:30:18.478426Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-12-29T08:30:18.558252Z 0 [Note] InnoDB: Completed initialization of buffer pool
2022-12-29T08:30:18.560435Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2022-12-29T08:30:18.583358Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2022-12-29T08:30:18.639774Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-12-29T08:30:18.639877Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-12-29T08:30:18.730990Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-12-29T08:30:18.731839Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2022-12-29T08:30:18.731857Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2022-12-29T08:30:18.747527Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 2630592
2022-12-29T08:30:18.759639Z 0 [Note] Plugin 'FEDERATED' is disabled.
2022-12-29T08:30:18.760211Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-12-29T08:30:18.785128Z 0 [Note] InnoDB: Buffer pool(s) load completed at 221229 16:30:18
2022-12-29T08:30:18.852248Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2022-12-29T08:30:18.852302Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2022-12-29T08:30:18.853091Z 0 [Warning] CA certificate ca.pem is self signed.
2022-12-29T08:30:18.853145Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2022-12-29T08:30:18.854334Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2022-12-29T08:30:18.854569Z 0 [Note] IPv6 is available.
2022-12-29T08:30:18.854591Z 0 [Note] - '::' resolves to '::';
2022-12-29T08:30:18.854618Z 0 [Note] Server socket created on IP: '::'.
2022-12-29T08:30:18.862692Z 0 [Note] Event Scheduler: Loaded 0 events
2022-12-29T08:30:18.863062Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.29' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
第7行内容即临时密码bE/gJI;_f7Is(注意字符串前后没有空格)
行数可能不同,找到A temporary password即可
2022-12-29T08:28:35.060793Z 1 [Note] A temporary password is generated for root@localhost: bE/gJI;_f7Is
修改密码、授权、自启
[root@hadoop1 mysql5.7.29]# mysql -u root -p
Enter password:
此处粘贴上述初始密码,内容不可见,直接回车即可
[root@hadoop1 mysql5.7.29]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29Copyright (c) 2000, 2020, 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>
修改密码 ,在“”内输入密码,如:alter user user() identified by "123456";
mysql> alter user user() identified by "这里是你的密码";
Query OK, 0 rows affected (0.00 sec)
授权(本人需要配置Hive,因此授权MySQL远程使用,无Hive需求跳过此步骤)
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 -ADatabase changed
mysql>
mysql>
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql>
mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
Ctrl+D退出mysql
设置开机自启
[root@hadoop1 mysql5.7.29]# systemctl enable mysqld
查看是否设置成功
[root@hadoop1 mysql5.7.29]# systemctl list-unit-files | grep mysqld
mysqld.service enabled
mysqld@.service disabled
Hadoop学习笔记: