mysql登陆不上如故密码忘记可以品味一下无密码登陆

=

① 、通过yum举办安装


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

将从网站上复制的内容(如上)添加到空文件中并保存,自此玛丽亚DB的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.③ 、打开防火墙

外部访问玛丽亚DB,比如Java等链接,供给通过3306端口,由此须求开放3306端口:

[【澳门金沙国际】mysql无密码登陆,重置密码。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)]>

此刻,代表成功进去了玛丽亚DB环境。

能够通过如下格局查看当前抱有的数据库:

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数据库,而是采取玛丽亚DB数据库,当中玛丽亚DB是MySQL的贰个分支.今后写上个体在CentOS7里设置配置玛丽亚DB的步骤:

  1. 下载安装玛丽亚DB

**yum -y install mariadb-server mariadb

  1. 开发银行玛丽亚DB,并安装root用户的密码:

#启动MariaDB服务
**

[[email protected]
/]# systemctl start mariadb

#安装玛丽亚DB开机私下认可运转
[[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

#在生育环境里安装完后,提出一定要运转2回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)

安装 玛丽亚DB
CentOS7以上版本上,不再动用MySQL数据库,而是选择玛丽亚DB数据库,在那之中玛丽亚DB是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

相关文章