linux 安装mysql5.7+

下载安装

1.首先检测系统是否已安装MySQL

sudo netstat -tap | grep mysql

若没有反映,没有显示已安装结果,则没有安装

2.安装MySQL

sudo apt-get install mysql-server mysql-client

3.测试是否成功

sudo netstat -tap | grep mysql

tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN      10457/mysqld  

4.查看版本

mysql --version

我的是 5.7.24

踩坑

登录mysql

mysql -u root -p

提示密码错误,以前的版本是安装过程中会提示你输入root用户密码,但这次没有,也有的说是空格,但还是没有用,按照常理找到 my.cnf,设置跳过密码登录,LZ的my.cnf文件在 /etc/mysql 下

cat my.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

就只有 !includedir /etc/mysql/conf.d/ 和 !includedir /etc/mysql/mysql.conf.d/ 两行
打开 /etc/mysql/mysql.conf.d/mysqld.cnf 的文件,才是我们真正的配置文件

sudo nano mysqld.cnf

部分配置如下

[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

[mysqld]
#
# * Basic Settings
#
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
lc-messages-dir	= /usr/share/mysql
skip-external-locking
skip-grant-tables
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address		= 127.0.0.1
#

打开之后,在mysqld 后加入 skip-grant-tables ,Ctrl + X ,选择 y, 保存退出

重启

service mysql restart

在执行 mysql -u root -p 密码随便输,就可以登录进去

进去之后 ,执行

use mysql;

修改密码

update user set authentication_string=password(‘admin’) where user=’root’ and host=’localhost’;

刷新

flush privileges;

此时执行 \q; 退出

再次执行 mysql -u root -p,报错如下

ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded

解决(原因暂不详) ,再次重启 mysql 即可 service mysql restart
记得改完密码后,注释掉 skip-grant-tables,
此时你在登录mysql就没有问题了

以上只是安装过程中遇到的问题,自己解决的办法,有些还不知道原因

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值