Linux下安装Mysql5.7.x数据库

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 乌班图系统安装mysql过程中遇到的坑,在此记录

首先检查是否存在mariadb 如果存在需要卸载
ps -ef| grep mariadb
mysql    31760 28814  0 18:16 pts/1    00:00:00 grep --color=auto mariadb
 
rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
卸载
rpm -e mariadb-libs-5.5.52-1.el7.x86_64
会提示有依赖于这的安装包,那么就强制卸载,不查检依赖:
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
将所有的mariadb安装包都删除,然后自行安装MySQL就可以了

1---->rpm -qa|grep -i mysql 检查是否已经有安装,可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系
2---->检查用户组是否存储cat /etc/group | grep mysql
检查用户是否存在cat /etc/passwd | grep mysql
[mysql@oracledb_178 ~]$ cat /etc/group | grep mysql
mysql:x:1002:
[mysql@oracledb_178 ~]$ cat /etc/passwd | grep mysql
mysql:x:1001:1002::/home/mysql:/bin/bash

3---->如果不存在新建
groupadd mysql 建立用户组
useradd -r -g mysql mysql 建立用户 useradd -r参数表示mysql用户是系统用户,不可用于登录系统
进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户
chown -R mysql .
chgrp -R mysql .
4---->解压
tar xvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 
mv mysql-5.7.18-linux-glibc2.5-x86_64 ../mysql-5.7.18

5---->执行mysql_install_db脚本 报错 mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-09-01 11:50:57 [ERROR]   The data directory needs to be specified.mysql_install_db 已经不再推荐使用了,建议改成 mysqld –initialize 完成实例初始化
5.7.X的版本使用mysqld
执行命令:
./mysqld --user=mysql --datadir=/home/mysql/mysql-5.7.18/data --basedir=/home/mysql/mysql-5.7.18  --initialize
结果如下:必须记住A temporary password is generated for root@localhost: Cuc_gue<B7Li
 
017-09-01T10:22:39.683534Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-09-01T10:22:39.683770Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-09-01T10:22:39.684125Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-01T10:22:42.210352Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-09-01T10:22:42.696775Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-09-01T10:22:42.776470Z 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: 7d47ff18-8eff-11e7-
9079-000c2918d28c.2017-09-01T10:22:42.780141Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-09-01T10:22:42.781062Z 1 [Note] A temporary password is generated for root@localhost: Cuc_gue<B7Li

 
6----> 检测一下是否能启动
./mysql.server start
./mysql.server: line 239: my_print_defaults: command not found
./mysql.server: 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)
修改./mysql.server文件的
basedir=/home/mysql/mysql-5.7.18
datadir=/home/mysql/mysql-5.7.18/data
执行
$ ./mysql.server start
Starting MySQL. SUCCESS! 

 
6---->配置my.cnf
[mysqld]
basedir=/home/mysql/mysql-5.7.18
datadir=/home/mysql/mysql-5.7.18/data
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
[mysqld_safe]
log-error=/home/mysql/mysql-5.7.18/data/error.log
pid-file=/home/mysql/mysql-5.7.18/data/oracledb_178.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
 
7---->拷贝启动文件到/etc/init.d/下并重命令为mysqld
cp /home/mysql/mysql-5.7.18/support-files/mysql.server /etc/init.d/mysqld
 
8------->增加执行权限
chmod 755 /etc/init.d/mysqld
 
9------->检查自启动项列表中没有mysqld这个,如果没有就添加mysqld:
chkconfig --list mysqld
chkconfig --add mysqld
 
10---------->用这个命令设置开机启动:
chkconfig mysqld on
 
11---------->停止mysql服务
service mysqld stop
重启mysql服务
service mysqld restart
12--->初始化mysql用户root的密码
先将mysql服务停止
# service mysqld stop
 
进入mysql安装目录,
 
cd mysql-5.7.18/bin
执行
./mysqld_safe --skip-grant-tables --skip-networking&
 
然后打开另一个新的ssl窗口
cd mysql-5.7.18/bing
./mysql -u root mysql
执行
mysql> use mysql;
Database changed 
mysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root'; 
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> 
update user set authentication_string = PASSWORD('123456') where user = 'root'; 
 
执行 mysql>\s 
--------------
./mysql  Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using  EditLine wrapper
Connection id: 3
Current database: mysql
Current user: root@
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.18 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db     characterset: latin1
Client characterset: utf8
Conn.  characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 3 min 57 sec
 
Threads: 1  Questions: 43  Slow queries: 0  Opens: 127  Flush tables: 1  Open tables: 52  Queries per second avg: 0.181
--------------
 
mysql> exit; 
 
12--->重新启动mysql服务, 用新密码连接mysql
mysql@oracledb_178 bin]$ ./mysql -uroot -p
13---> 远程授权
grant all privileges on *.* to 'root'@'%' identified by '123456'; 
grant all on *.* to 'root'@'%' identified by '123456';  
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
 
出现上面的错误只需要执行mysql>flush privileges;
 
在执行
mysql> grant all on *.* to 'root'@'%' identified by '123456'; 
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
客户端navacat无法连接关闭防火墙
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
 
12--->最后重新启动一下,然后客户端就可以连接mysql了

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
40 1
|
4天前
|
关系型数据库 MySQL 分布式数据库
《MySQL 简易速速上手小册》第6章:MySQL 复制和分布式数据库(2024 最新版)
《MySQL 简易速速上手小册》第6章:MySQL 复制和分布式数据库(2024 最新版)
31 2
|
4天前
|
关系型数据库 MySQL 数据库
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
27 4
|
1天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
10 0
|
1天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
8 0
|
1天前
|
SQL 存储 关系型数据库
数据库开发之mysql前言以及详细解析
数据库开发之mysql前言以及详细解析
9 0
|
1天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(7)Ubuntu20.04 arm64安装Docker
Linux(7)Ubuntu20.04 arm64安装Docker
8 0
|
4天前
|
Linux
ZooKeeper的安装(Linux版)
ZooKeeper的安装(Linux版)
16 1
|
4天前
|
应用服务中间件 Linux 网络安全
Tomcat的安装(Linux版)
Tomcat的安装(Linux版)
17 0
|
6天前
|
SQL 关系型数据库 MySQL
MySQL环境搭建——“MySQL数据库”
MySQL环境搭建——“MySQL数据库”