您尚未登录。

楼主 #1 2019-12-25 16:57:39

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

ubuntu 18.04 重设 mysql 服务器密码

https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password-on-ubuntu-18-04

总结一下:


进入维护模式:

#启动不加载授权表或网络功能#
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking"

#重启数据库服务器#
sudo service mysql restart


sudo mysql -u root

mysql 命令行输入以下命令:

mysql> use mysql
mysql> FLUSH PRIVILEGES;
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('whycan') WHERE user = 'root';
mysql> UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root';
mysql> exit

直接复制:

use mysql
FLUSH PRIVILEGES;
UPDATE mysql.user SET authentication_string = PASSWORD('whycan') WHERE user = 'root';
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root';
exit

恢复正常运行:

#复位环境变量#
sudo systemctl unset-environment MYSQLD_OPTS

#重启数据库服务器#
sudo service mysql restart

搞定!

离线

#2 2019-12-25 17:01:15

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,224
积分: 9197

Re: ubuntu 18.04 重设 mysql 服务器密码

不错, 感谢分享!





离线

楼主 #3 2019-12-25 17:46:16

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

晕哥 说:

不错, 感谢分享!

^_^ 感谢这么好的网站, 刚好搭公司OA服务器,随手记录,怕过几天又忘记流程了。

离线

楼主 #4 2019-12-25 17:48:38

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

This PHP environment doesn't have MySQL support built in. MySQL support is required if you want to use a MySQL database to run this forum. Consult the PHP documentation for further assistance.

phpmyadmin 访问数据库正常,并且已经把数据库正常导入了。

但是把祖传的OA软件搭上去之后, 出现上面这个错误。

百思不得其解, 后来发现

https://stackoverflow.com/questions/35424982/how-can-i-enable-the-mysqli-extension-in-php-7

居然:

Let's use

mysqli_connect

instead of

mysql_connect

because mysql_connect isn't supported in php7.

原来是 php7 已经不再支持 mysql 接口了, 只支持 mysqli 和 pdo mysql接口。

离线

楼主 #5 2019-12-25 17:53:47

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

发现 ubuntu 18.04 居然没有了 php5 安装包了。


囧囧囧

离线

楼主 #6 2019-12-25 18:00:35

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

找到一个网站
https://vitux.com/how-to-install-php5-and-php7-on-ubuntu-18-04-lts/

据说可以安装 php5

试一试:

sudo apt-get update
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.6

离线

楼主 #7 2019-12-25 19:16:43

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

费了九牛二虎之力,终于把 php5.6 怼上了 ubuntu18.04,

现在出现了:

phpMyAdmin - Error
The mbstring extension is missing. Please check your PHP configuration.

离线

楼主 #8 2019-12-25 19:20:28

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

我心飞翔 说:

费了九牛二虎之力,终于把 php5.6 怼上了 ubuntu18.04,

现在出现了:

搞定了上面的问题了:
sudo apt-get install php5.6-mbstring -y

出现新的问题:

缺少 mysqli 扩展。请检查 PHP 配置。 详情请查看我们的文档。

离线

楼主 #9 2019-12-25 19:36:41

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

我心飞翔 说:

搞定了上面的问题了:
sudo apt-get install php5.6-mbstring -y

出现新的问题:

搞定:
sudo apt-get install php5.6-mysql -y

离线

楼主 #10 2019-12-26 08:47:00

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

睡了一觉, 今天继续。

发现一打开 OA 网站, 就处于列目录状态,  无论怎么修改 .htaccess 都不起作用,

昨天晚上搞到深夜都没搞定。

今天早上查资料发现, /etc/apache 目录下面的相关设置会影响 .htaccess 是否被应用。

马上修改

/etc/apache2/sites-available/bagong.oa.conf

        <Directory /var/www/bagong.oa>
                AllowOverride All
                DirectoryIndex index.html index.htm index.php
        </Directory>

这样,  /var/www/bagong.oa/public/.htaccess

Options -Indexes

就正常了, 打开主页也不列目录了。

离线

楼主 #11 2019-12-26 08:54:04

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

默认访问 oa.php, 需要修改 .htaccess:

Options -Indexes
DirectoryIndex oa.php

离线

楼主 #12 2019-12-26 11:00:41

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

oa 的 附件指向别的目录, 是软链接的, 网页打开就错了, 可能要设置 FollowSymLinks 属性, 晚点处理一下。

离线

#13 2020-02-25 16:03:24

春风吹又生
会员
注册时间: 2020-02-25
已发帖子: 61
积分: 60

Re: ubuntu 18.04 重设 mysql 服务器密码

我心飞翔 说:

找到一个网站
https://vitux.com/how-to-install-php5-and-php7-on-ubuntu-18-04-lts/

据说可以安装 php5

试一试:

牛, 百度了一天,终于找到一个靠谱的答案了,谢谢楼主, 谢谢这个牛皮的网站。



新建了一个腾讯云ubuntu18.04实例,总结一下:

sudo apt-get update; \
sudo apt-get install software-properties-common -y; \
sudo add-apt-repository ppa:ondrej/php; \
sudo apt-get update; \
sudo apt-get install -y php5.6; \
sudo apt-get install apache2 mysql-server composer -y; \
sudo apt-get install php5.6-curl php5.6-mbstring php5.6-mysql -y;

#设置阿里云镜像  https://whycan.cn/t_3680.html
sudo composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

#下载thinkphp5
sudo composer create-project topthink/think  ./ 5.1.39

离线

#14 2020-03-03 16:53:14

光头程序员
会员
注册时间: 2020-03-03
已发帖子: 14
积分: 14

Re: ubuntu 18.04 重设 mysql 服务器密码

一楼的方法估计是不需要或者忘记 mysql root 的密码, 然后强行重置root密码


如果记得密码, 可以用这个方法改密码:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

MySQL5.7 以后的版本得用这个:

UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE user='root';
FLUSH PRIVILEGES;

参考1: https://stackoverflow.com/questions/7534056/mysql-root-password-change/18100189
参考2: https://www.a2hosting.com/kb/developer-corner/mysql/reset-mysql-root-password

离线

楼主 #15 2020-04-02 11:44:45

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: ubuntu 18.04 重设 mysql 服务器密码

https://www.digitalocean.com/community/questions/no-password-is-asked-when-installing-mysql-server

sudo mysql_secure_installation

这个也可以重置  mysql server 密码。

离线

#16 2020-04-14 11:20:12

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Re: ubuntu 18.04 重设 mysql 服务器密码

mysql> select VERSION() ;
+-------------------------+
| VERSION()               |
+-------------------------+
| 5.7.29-0ubuntu0.18.04.1 |
+-------------------------+
1 row in set (0.00 sec)

命令行进入正常, 但是 pma 提示:

#1698 - Access denied for user 'root'@'localhost'

mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost'


一脸懵x

离线

#17 2020-04-14 11:27:42

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Re: ubuntu 18.04 重设 mysql 服务器密码

https://devanswers.co/phpmyadmin-access-denied-for-user-root-localhost/

找到问题了, 可能 phpmyadmin 禁用了root登录,需要重新注册一个用户才行:

CREATE USER 'pmauser'@'localhost' IDENTIFIED BY 'password_here';
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost' WITH GRANT OPTION;

记得密码要 大小写字母和特殊字符,密码长度也有要求,否则一样会提示楼上一样的错误。

离线

#18 2020-04-14 14:11:38

pythinker
会员
注册时间: 2019-02-12
已发帖子: 215
积分: 215

Re: ubuntu 18.04 重设 mysql 服务器密码

在MySQL5.6跑得好好的代码,到5.7就出问题了:

#1140 - In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'bb_20200414.f.forum_name'; this is incompatible with sql_mode=only_full_group_by

解决方案: http://xstarcd.github.io/wiki/MySQL/MySQL-sql-mode.html

打开 /etc/mysql/my.cnf 添加:

[mysqld]
#set the SQL mode to strict
sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

离线

#19 2020-08-28 22:35:44

awfans
会员
注册时间: 2018-04-03
已发帖子: 264
积分: 264

Re: ubuntu 18.04 重设 mysql 服务器密码

感谢楼主分享, 一楼那个重置 root 密码的命令行可以用.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql>
mysql> select authentication_string from user;
+-------------------------------------------+
| authentication_string                     |
+-------------------------------------------+
|                                           |
| *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| *384DF59F36979048940D28EE1FB7B068A79D5FDD |
+-------------------------------------------+
4 rows in set (0.00 sec)

mysql>
mysql>
mysql> select User,authentication_string from user;
+------------------+-------------------------------------------+
| User             | authentication_string                     |
+------------------+-------------------------------------------+
| root             |                                           |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| debian-sys-maint | *384DF59F36979048940D28EE1FB7B068A79D5FDD |
+------------------+-------------------------------------------+
4 rows in set (0.00 sec)

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('whycan') WHERE user = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> select authentication_string from user;
+-------------------------------------------+
| authentication_string                     |
+-------------------------------------------+
| *FAFBF4B590C56408440484A17E27C30A2635F64A |
| *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| *384DF59F36979048940D28EE1FB7B068A79D5FDD |
+-------------------------------------------+
4 rows in set (0.00 sec)
$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('whycan') WHERE user = 'root';
Query OK, 0 rows affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 1

mysql> UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> exit
Bye

Ubuntu18.04安装mysql默认是没有密码设置的菜单, 装好之后mysql是空密码.

跑完上面的命令之后, 执行 service apache2 restart 就可以使用新密码了.

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn