开发者社区> 心月狐> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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了

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
linux上安装redis
Redis Redis在linux上安装 将redis-3.0.7.tar.gz上传到linux虚拟机上 编译:     a)       因为redis是C语言开发,所以需要先编译,在linux上编译需要依赖gcc环境,如果没有安装gcc环境,需要安装gcc: 执行命令:yum install...
816 0
+关注
心月狐
暂无后续补充
34
文章
1
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载