下载安装
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就没有问题了
以上只是安装过程中遇到的问题,自己解决的办法,有些还不知道原因