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

简介: 乌班图系统安装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了

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
805 158
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
2090 152
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
1436 156
|
安全 Linux iOS开发
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
1049 6
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
SQL 关系型数据库 MySQL
Mysql数据恢复—Mysql数据库delete删除后数据恢复案例
本地服务器,操作系统为windows server。服务器上部署mysql单实例,innodb引擎,独立表空间。未进行数据库备份,未开启binlog。 人为误操作使用Delete命令删除数据时未添加where子句,导致全表数据被删除。删除后未对该表进行任何操作。需要恢复误删除的数据。 在本案例中的mysql数据库未进行备份,也未开启binlog日志,无法直接还原数据库。
1153 2
|
消息中间件 Kafka Linux
Linux下安装Kafka 3.9.1
本文介绍Kafka 3.9.1版本的安装与配置,包括通过ZooKeeper或KRaft模式启动Kafka。涵盖环境变量设置、日志路径修改、集群UUID生成、存储格式化及服务启停操作,适用于Linux环境下的部署实践。
1610 0
|
Linux Shell 数据库
linux乱码和数据库乱码的问题简单排查
在本地的虚拟机环境一直凑合着用英文,今天想看看中文的东西都显示乱码,下定决心要把问题解决了。 如果直接打印文本内容,通过putty也会显示乱码。 [ora11g@rac1 ~]$ cat aa.sh δ? ε??ο?θ?ζ―δ?δ??ζ?θ― [ora11g@rac1 ~]$ 这个时候很可能是putty的编码转换的问题,通过查看putty的设置,如上,可以看到应该选为utf-8。
1202 0

热门文章

最新文章