ubuntu18.04安装mysql以及重置密码创建新用户
1、安装mysql
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
通过sudo netstat -tap | grep mysql检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功
现在配置mysql允许远程访问,首先编辑 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:
vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address = 127.0.0.1
修改了密码也不对。然后sudo mysql -u root即可登录。这显然不是我们想要的。
2、创建新用户
首先,登录
sudo mysql -u root
1
然后查看当前用户
SELECT User,Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| admin | localhost |
| debian-sys-maint | localhost |
| magento_user | localhost |
| mysql.sys | localhost |
| root | localhost |
mysql> CREATE USER 'test'@'%' IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0,00 sec)
授权
mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0,00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0,01 sec)
3、关于重置密码
host为%时允许远程登录
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
or
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
or
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = 'localhost' AND User = 'root';
允许任何地方登录
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = '%' AND User = 'root';
运行一下
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
什么鬼,为什么会出现这个错误呢?我明明设置的是 localhost,为什么会变成 127.0.0.1?
解决问题
照例先谷歌,确实发现了很多人也遇到了这个问题,解决方法大概有这么几种:
1、你丫以为不用装 MySQL 就能跑了么?快去装数据库!
2、你数据库运行了么你?赶紧 /etc/init.d/mysqld start 运行起来
3、端口写错了
4、你是不是开启了 skip-networking 这个选项?Remove it !