操作系统

当前位置:金沙棋牌 > 操作系统 > 重置密码,mysql无密码登陆

重置密码,mysql无密码登陆

来源:http://www.logblo.com 作者:金沙棋牌 时间:2019-12-28 01:00

mysql登入不上照旧密码忘记能够尝尝一下无密码登录

=

1、通过yum举行安装


1.1、最初希图

先是供给到MariaDB网址(:

# MariaDB 10.1 CentOS repository list - created 2016-09-06 09:30 UTC

#

[mariadb]

name = MariaDB

baseurl =

gpgkey=

gpgcheck=1

创建yum库文件:

[root@myhost /]# vi /etc/yum.repos.d/MariaDB.repo

将从网址上复制的始末(如上)增多到空文件中并保存,今后MariaDB的yum库创立好了。


1.2、安装

通过yum举办安装,推行如下命令,就可以安装服务端和客商端:

[root@myhost /]# yum install –y MariaDB-server MariaDB-client

安装达成后,可以运转玛丽亚DB:

[root@myhost /]# systemctl start mariadb.service

设置开机自动运转:

[root@myhost /]# systemctl enable mariadb.service


1.3、张开防火墙

外表访谈MariaDB,比方Java等链接,需求经过3306端口,由此必要开放3306端口:

[root@myhost /]# firewall-cmd --permanent --zone=public --add-port=3306/tcp

success

内部permanent 参数将防火墙设置为世代的。


1.4、查看数据库

开端安装后,能够查阅默许的数据库,理解安装是或不是中标,当时亟需步向mariaDB数据库的调整嘉义开展查看。

刚安装好后,间接走入调控台无需其他权力:

[root@myhost /]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or g.

Your MariaDB connection id is 3

Server version: 10.1.17-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

此时,代表成功进去了MariaDB际遇。

可以通过如下方式查看当前具有的数据库:

MariaDB [(none)]> show databases;

+--------------------+

| Database            |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test                |

+--------------------+

4 rows in set (0.06 sec)

MariaDB [(none)]>


1.5、配置root用户

root权限要求在mysql数据库中期维改进,因而要求先踏入mysql数据库境遇:

MariaDB [(none)]> 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

MariaDB [mysql]>

跻身mysql数据库意况后,为root客户更新密码,并付与权力:

MariaDB [mysql]> update user set password=password("xxxxxx") where user='root';

Query OK, 0 rows affected (0.00 sec)

Rows matched: 4 Changed: 0 Warnings: 0

MariaDB [mysql]>

为root顾客付与权力:

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]>

最后索要退出,比量齐观新登入:

MariaDB [mysql]> exit

Bye

[root@myhost /]#

此刻当再一次登入时,需求钦定登陆客户,以至能够直接输入密码:

MariaDB [mysql]> mysql -u root -p123456

Welcome to the MariaDB monitor.  Commands end with ; or g.

Your MariaDB connection id is 3

Server version: 10.1.17-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

p参数(密码)供给一向与密码明文拼接。

若仅输入参数p,则中期会必要输入密码:

[root@myhost /]# mysql -u root -p

Enter password:

CentOS7 安装 MariaDB

CentOS7上述版本上,不再行使MySQL数据库,而是利用MariaDB数据库,在那之中MariaDB是MySQL的叁个分支.以后写上个体在CentOS7里设置配备MariaDB的手续:

  1. 下载安装MariaDB

**yum -y install mariadb-server mariadb

  1. 启航MariaDB,并设置root客商的密码:

#启动MariaDB服务
**

[[email protected] /]# systemctl start mariadb

#设置MariaDB开机暗中同意运营
[[email protected] /]# systemctl enable mariadb

ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'

#测量试验是或不是成功运营
[[email protected] /]# mysql
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 3
Server version: 5.5.47-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

#查阅暗中认可安装了什么样数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

#退出
MariaDB [(none)]> exit
Bye

#在生育条件里设置完后,建议应当要运营一遍mysql_secure_installation安全安插向导
[[email protected] /]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

#鉴于一发端安装玛丽亚DB数据库后, root客商暗中同意密码为空, 所以只要求按Enter键
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

#是或不是设置root顾客的新密码

Set root password? [Y/n] y

#录入新密码

New password:

#料定新密码

Re-enter new password:

Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

#是还是不是删除佚名用户,临蓐情况提出删除
Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

#是或不是幸免root远程登陆,根据本人的须求选取
Disallow root login remotely? [Y/n] n
... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

#是或不是删除test数据库
Remove test database and access to it? [Y/n] y

  • Dropping test database...
    ... Success!
  • Removing privileges on test database...
    ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

#是或不是再一次加载权限表
Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

#安全设置完毕后,测验使用root顾客登入操作
[[email protected] /]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 13
Server version: 5.5.47-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

安装 MariaDB CentOS7上述版本上,不再使用MySQL数据库,而是利用玛丽亚DB数据库,个中MariaDB是MySQL的多个分支.今后写上个人在CentOS7里安装配置...

 

心烦,ubuntu以命令生势势mariadb,安装进度中从不现身输入root客户的分界面,安装完mariadb,不理解root顾客密码,以root身份登录报如下错误:

以下一波神操作!!

david@david-pc:~$ MySQL -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

 

减轻步骤:

第黄金时代关闭数据库服务(数据库在Centos7版本以上只怕Redhat版本上被改名换姓为mariadb)

1.sudo身份开垦 /etc/mysql/my.cnf
在【mysqld】节点下扩大如下代码:

systemctl stop mariadb

skip-grant-tables #马虎密码授权

跳过密码验证(& 将该进程放到后台运营)
mysqld_safe --skip-grant-tables &
直白运用MySQL无密码登陆

2.杀掉mysql进程,重启mariadb,这时候直接mysql -uroot -p,不供给密码就能够登入进mysql。

[root@Darius ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 1
Server version: 5.5.44-MariaDB MariaDB Server

david@david-pc:/etc$ mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 9
Server version: 10.0.28-MariaDB-1 Debian unstable

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

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

MariaDB [(none)]>

MariaDB [(none)]>

改善密码

3.登陆后,修改root密码:

 

use mysql;

MariaDB [(none)]> update mysql.user set password=password('123456') where user='root';
ps -aux|grep mysql找到pid,kill杀死Mariadb进程
重启Mariadb服务

update mysql.user set password=PASSWORD('YOUR_PASSWORD') where user='root';

4.sudo身份开采 /etc/mysql/my.cnf
在【mysqld】节点投注释如下代码:

#skip-grant-tables

5. 重启mariadb

sudo service mysql restart

本文由金沙棋牌发布于操作系统,转载请注明出处:重置密码,mysql无密码登陆

关键词: