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


首先检查是否存在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
[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了

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值