centos7环境使⽤mysql离线安装包安装mysql5.7
服务器环境:centos7 x64
需要安装mysql5.7+
⼀、卸载CentOS7系统⾃带mariadb
# 查看系统⾃带的Mariadb
[root@CDH-141 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.s.x86_64tensorflow怎么打开
# 卸载系统⾃带的Mariadb(rpm -e --nodeps)
[root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.s.x86_64
# 删除etc⽬录下的myf
[root@CDH-141 ~]# rm /etc/myf
⼆、检查mysql是否存在
# 检查mysql是否存在
[root@CDH-141 ~]# rpm -qa | grep mysql
[root@CDH-141 ~]#
三、查看⽤户和组是否存在
1)检查mysql组合⽤户是否存在
# 检查mysql组和⽤户是否存在,如⽆则创建
[root@CDH-141 ~]# cat /etc/group | grep mysql
[root@CDH-141 ~]# cat /etc/passwd | grep mysql
# 查询全部⽤户(只是做记录,没必要执⾏)
[root@CDH-141 ~]# cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":" '{print $1 "|" $3 "1" $4}' | more
root|010
sync|510
flume|9921989
hdfs|9911988
zookeeper|9891986
llama|9881985
httpfs|9871984
mapred|9861983
sqoop|9851982
yarn|9841981
kms|9831980
hive|9821979
oozie|9801977
hbase|9781975
impala|9761973
hue|9741971金山表单
wlaqzc2018|100111001
[root@CDH-141 mysql]#
2)若不存在,则创建mysql组和⽤户
# 创建mysql⽤户组
[root@CDH-141 ~]# groupadd mysql
# 创建⼀个⽤户名为mysql的⽤户,并加⼊mysql⽤户组
script loaded什么意思
[root@CDH-141 ~]# useradd -g mysql mysql
# 制定password 为111111 (⽤户mysql的密码)
[root@CDH-141 ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
四、下载mysql离线安装包tar⽂件
官⽹下载地址:
版本选择,可以选择⼀下两种⽅式:
1)使⽤Red Hat Enterprise Linux
Select Version:5.7.35
Select Operating System:Red Hat Enterprise Linux / Oracle Linux
Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
列表中下载:
Compressed TAR Archive:(mysql-5.7.35-el7-x86_)
2)使⽤Linux - Generic
Select Version:5.7.35
Select Operating System:Linux - Generic
Select OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
列表中下载:
Compressed TAR Archive:(mysql-5.7.35-linux-glibc2.12-x86_)【本⽂中使⽤的是这个版本】
注意:上边两种⽅式mysql离线安装包的⽅式都可以。
五、上传第四步下载的mysql TAR包
# 进⼊/usr/local/⽂件夹
[root@CDH-141 ~]# cd /usr/local/
# 上传mysql TAR包
[root@CDH-141 local]# rz
# 解压mysql-5.7.35-linux-glibc2.12-x86_
[root@CDH-141 local]# tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_
bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_ share
etc games lib libexec sbin src
[root@CDH-141 local]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_
mysql-5.7.25-lin
...
mysql-5.7.25-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-5.7.25-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/magic
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC
[root@CDH-141 local]# ls
bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_ share
etc games lib libexec mysql-5.7.25-linux-glibc2.12-x86_64 sbin src
# 进⼊/usr/local下,修改为mysql
[root@CDH-141 local]# mv mysql-5.7.35-linux-glibc2.12-x86_64 mysql
[root@CDH-141 local]# ls
bin etc full-path-to-mysql-VERSION-OS games include lib lib64 libexec mysql mysql-5.7.35-linux-glibc2.12-x86_ sbin share src 六、更改所属的组和⽤户
# 更改所属的组和⽤户
[root@CDH-141 ~]# cd /usr/local/
[root@CDH-141 local]# chown -R mysql mysql/
[root@CDH-141 local]# chgrp -R mysql mysql/
[root@CDH-141 local]# cd mysql/
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]# chown -R mysql:mysql data
备注:
chown -R mysql:mysql ./
chown [选项]... [所有者][:[组]] ⽂件...
必要参数:
-c 显⽰更改的部分的信息
-f 忽略错误信息
-h 修复符号链接
-R 处理指定⽬录以及其⼦⽬录下的所有⽂件
-v 显⽰详细的处理信息
-deference 作⽤于符号链接的指向,⽽不是链接⽂件本⾝
选择参数:
--reference=<⽬录或⽂件> 把指定的⽬录/⽂件作为参考,把操作的⽂件/⽬录设置成参考⽂件/⽬录相同拥有者和组
--from=<;当前⽤户:当前组> 只有当前⽤户和组跟指定的⽤户和组相同时才进⾏改变
--help 显⽰帮助信息
--version 显⽰版本信息
七、在/etc下创建myf⽂件
# 进⼊/usr/local/mysql⽂件夹下
[root@CDH-141 ~]# cd /usr/local/mysql
# 创建myf⽂件
[root@CDH-141 mysql]# touch myf # 或者 cd ''&f
# 编辑myf
[root@CDH-141 mysql]# f
[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8
[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port
port = 3323 #默认是3306,这⾥发现3306已经被占⽤,因此防⽌这种情况发⽣,可以避免使⽤3306mysql默认端⼝
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
[mysql.server]
user=mysql #⽤户不是mysql时,更改此处
basedir=/usr/local/mysql
[root@CDH-141 mysql]#
⼋、进⼊mysql⽂件夹,并安装mysql
# 进⼊mysql
[root@CDH-141 local]# cd /usr/local/mysql
# 安装mysql
[root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-03-08 18:11:24 [WARNING] The bootstrap log isn't empty:
2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
设置⽂件及⽬录权限:
[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@CDH-141 mysql]# chown 777 myf
[root@CDH-141 mysql]# ls
bin COPYING data docs include lib man myf README share support-files
[root@CDH-141 mysql]# ls -l
total 60
drwxr-xr-x 2 root root 4096 Mar 8 15:56 bin
-rw-r--r-- 1 7161 31415 17987 Dec 21 18:39 COPYING
drwxr-x--- 5 mysql mysql 4096 Mar 8 16:21 data
drwxr-xr-x 2 root root 4096 Mar 8 15:56 docs
drwxr-xr-x 3 root root 4096 Mar 8 15:56 include
drwxr-xr-x 5 root root 4096 Mar 8 15:56 lib
drwxr-xr-x 4 root root 4096 Mar 8 15:56 man
-rw-r--r-- 1 777 root 516 Mar 8 16:19 myf
-rw-r--r-- 1 7161 31415 2478 Dec 21 18:39 README
drwxr-xr-x 28 root root 4096 Mar 8 15:56 share
drwxr-xr-x 2 root root 4096 Mar 8 15:56 support-files
[root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld
[root@CDH-141 mysql]#
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]#
[root@CDH-141 mysql]# chown -R mysql:mysql data
[root@CDH-141 mysql]#
九、启动mysql
# 启动mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found![FAILED]
Starting MySQL.Logging to '/usr/local/mysql/'.
.
.The server quit without updating PID file (/usr/local/mysql/data/CDH-141.pid).[FAILED]
[root@CDH-141 mysql]#
出现错误,解决⽅案如下:
#到是否已经有进程占⽤
[root@CDH-141 mysql]# ps aux|grep mysql
root 32483 0.0 0.0 113252 1620 pts/0 S 18:04 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/CDH-141.pid
mysql 32684 0.1 0.1 1119892 178224 pts/0 Sl 18:04 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql -- --pid-file=/usr/local root 35137 0.0 0.0 112648 944 pts/0 S+ 18:12 0:00 grep --color=auto mysql
#关闭进程
[root@CDH-141 mysql]# kill -9 32684
[root@CDH-141 mysql]# /usr/local/mysql/bin/mysqld_safe: line 198: 32684 Killed nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --u #确认是否还占⽤
[root@CDH-141 mysql]# ps aux|grep mysql
root 35501 0.0 0.0 112644 948 pts/0 S+ 18:13 0:00 grep --color=auto mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found![FAILED]
Starting MySQL..[ OK ]
[root@CDH-141 mysql]#
# 重启mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL..[ OK ]
Starting MySQL..[ OK ]
[root@CDH-141 mysql]#
在Linux<CentOS>服务器上安装Mysql,由于Centos⾃⾝的yum源中⽤Mysql的分⽀Mariadb代替了MySQL,所以不得不选择rpm或包的⽅式安装,
但是为了以后在其他LInux如Ubuntu中也能熟练安装MySQL,所以推荐使⽤
运⾏命令:service mysqld start
出现如下错误:
Starting MySQL.Logging to '/usr/mysql/mysql-5.7.35/data/'.
2021-08-13T01:01:52.896471Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/usr/mysql/mysql-5.7.35/data/localhost.localdomain.pid).
执⾏命令:cat /usr/mysql/mysql-5.7.35/data/查看错误原因
error内容如下:
[ERROR] Can't start server : Bind on unix socket: Permission denied
[ERROR] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
结合先前写⼊配置/etc/myf:
由上不难理解——
第⼀:
mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
“var/lib/mysql”⽬录不存在,⾸要先创建:
mkdir /var/lib/mysql
第⼆:
Mysql客户端和服务器端是通过初始化mysql.sock ⽂件来进⾏通信,所以服务器在启动时需要写⼊该⽂件,因此该⽂件所存放的⽬录必须双⽅都
具有访问权限。⽽异常⽇志中表⽰:
[ERROR] Can't start server : Bind on unix socket: Permission denied
所以,MySQL服务不具备⽬录 /var/lib/mysql 的写⼊权限,⽆法⽣成mysql.sock⽂件,⾃然服务启动时⽆法到该⽂件。
给⽬录 /var/lib/mysql 付予写⼊权限或者最⼤权限 chmod 777 /var/lib/mysql
最终:
————————————————
版权声明:本⽂为CSDN博主「:流花⿁」的原创⽂章,遵循CC 4.0 BY-SA版权协议,转载请附上原⽂出处链接及本声明。
centos和ubuntu原⽂链接:blog.csdn/qq_32331073/article/details/76229420
⼗、设置开机启动
#设置开机启动
[root@CDH-141 mysql]# chkconfig --level 35 mysqld on
[root@CDH-141 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
[root@CDH-141 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@CDH-141 mysql]# chkconfig --add mysqld
[root@CDH-141 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
[root@CDH-141 mysql]# service mysqld status
MySQL running (26122)[ OK ]
[root@CDH-141 mysql]#
⼗⼀、修改配置⽂件
# 进⼊/etc/profile⽂件夹
[root@CDH-141 mysql]# vim /etc/profile
安装tpshop教程修改/etc/profile,在最后添加如下内容
# 修改/etc/profile⽂件
#set mysql environment
export PATH=$PATH:/usr/local/mysql/bin
# 使⽂件⽣效
[root@CDH-141 mysql]# source /etc/profile
⼗⼆、获得mysql初始密码
1)获得mysql初始密码
[root@CDH-141 mysql]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2019-03-08 17:40:42
poc3u0mO_luv
[root@CDH-141 mysql]#
2)修改密码
[root@CDH-141 mysql]# mysql -uroot -p
Enter password: #此处填写上边获取到的初始密码‘poc3u0mO_luv’
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25
Copyright (c) 2000, 2015, 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> set PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
备注:
修改密码时报错:
Can't connect to local MySQL server through socket '/tmp/mysql.sock'
上述提⽰可能在启动mysql时遇到,即在/tmp/mysql.sock位置不到所需要的mysql.sock⽂件,主要是由于myf⽂件⾥对mysql.sock的位置设定导致。mysql.sock默认的是在/var/lib/mysql, 如果发现确实是在该⽬录下,可以在[mysqld]下⾯加⼊mysql.sock的path
vi /etc/myf(myf也可能在其他路径下)
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
但是要保证使⽤mysql的⽤户具有对该⽬录的写权限,否则这样的改动由于权限限制仍然会报错。
所以为了避免权限问题也可以使⽤软链接为/var/lib/mysql/mysql.sock创建⼀个到/tmp/mysql.sock的联接dimension命令什么意思
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
由于/tmp/⽂件夹默认对other有w权限,这样就可以避免权限问题。
此外,如果发现mysql.sock不在默认的/var/lib/mysql位置,⼀种解决⽅法是使⽤find命令搜索mysql.sock的位置,然后按前⾯两种解决⽅案挑⼀种做即可。
————————————————
版权声明:本⽂为CSDN博主「rush 2」的原创⽂章,遵循CC 4.0 BY-SA版权协议,转载请附上原⽂出处链接及本声明。
原⽂链接:blog.csdn/weixin_33026067/article/details/113219372
3)验证新密码是否登录成功:
[root@CDH-141 mysql]# mysql -uroot -p
Enter password: #此处输⼊新密码‘123456’
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
⼗三、添加远程访问权限
# 添加远程访问权限
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 host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql>
⼗四、重启mysql⽣效
# 重启mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL..[ OK ]
Starting MySQL..[ OK ]
[root@CDH-141 mysql]#
备注:
由于安装在/usr/local下⾯的mysql,因此可以在热河⽂件夹启动mysql
若安装在别的⽂件夹,请执⾏以下命令:
# 为了在任何⽬录下可以登录mysql
ln -s /你的mysql路径/mysql /usr/local/mysql
申明原贴:wwwblogs/yy3b2007com/p/10497787.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论