MySQL数据库localhost的root用户登陆遭遇失败
问题:Access denied for user 'root'@'localhost' (using password: YES)
打开MySQL目录下的my.ini文件(Linux的话是/etc/my.cnf),在文件的最后添加一行“skip-grant-tables”,保存并关闭文件。
2、重启MySQL服务。
3、在命令行中输入“mysql -uroot -p”(不输入密码),回车即可进入数据库。
4、执行,“use mysql;”使用mysql数据库。
5、执行,“update user set password=PASSWORD("rootadmin") where user='root';”(修改root的密码)
(期间我还select下user表中的记录,查询全部的时候显示了一些乱码,然后我只查询了user表中的Host、User、Password字段,貌似当时显示了3条记录,有1个没有名称。当然,为了解决问题,这些我也管不了了。)
6、打开MySQL目录下的my.ini文件,删除最后一行的“skip-grant-tables”,保存并关闭文件。
7、重启MySQL服务。
8、在命令行中输入“mysql -uroot -prootadmin”,问题搞定。
my.cnf的样例如下
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option. # The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
log-error=/alidata/log/mysql/error.log
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking # Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin # binary logging format - mixed recommended
binlog_format=mixed # required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1 # Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin # Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50 [mysqldump]
quick
max_allowed_packet = 16M [mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates [myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M [mysqlhotcopy]
interactive-timeout
MySQL数据库localhost的root用户登陆遭遇失败的更多相关文章
- MySQL数据库(13)----忘记root用户密码解决方案【转载】
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...
- Ansible 从MySQL数据库添加或删除用户
mysql_user - 从MySQL数据库添加或删除用户. 概要 要求(在执行模块的主机上) 选项 例子 笔记 状态 支持 概要 从MySQL数据库添加或删除用户. 要求(在执行模块的主机上) My ...
- 如何使Ubuntu Linux12.04 LTS版可以用root用户登陆
如何使Ubuntu Linux12.04 LTS版可以用root用户登陆 1. 用普通用户登录2. 在终端执行sudo -s,然后输入当前登录的普通用户密码,进入到root用户模式3. 执行ge ...
- ssh允许root用户登陆
新的系统无root用户密码,设置root用户密码,修改也是这么修改 sudo passwd root 连续输入两次新密码. 允许root用户登陆: /etc/ssh/sshd_config 找到 Pe ...
- 关于deepin下安装ssh以后root用户登陆报错的解决
最近刚刚接触到deepin,觉得,wow,除了mac,还有这么好看的非win系统,而且第测出那个Linux,宽容度很高,非常适合我这种比较喜欢折腾的人,于是下载了deepin15版本并将其当作虚拟机成 ...
- Mysql数据库中设置root密码的命令及方法
我们都知道通常PHP连接 Mysql都是通过root用户名和密码连接,默认情况下在Mysql安装时root初始密码为空,在安装使用PHP开源系统时,都需要填写连接Mysql数据库的用户名和密码,此时当 ...
- MySQL 5.7以上 root用户默认密码问题【转】
https://www.yanning.wang/archives/379.html 废话少说一句话系列: CentOS系统用yum安装MySQL的朋友,请使用 grep "temporar ...
- MySQL 5.7以上 root用户默认密码问题
废话少说一句话系列: CentOS系统用yum安装MySQL的朋友,请使用 grep "temporary password" /var/log/mysqld.log 命令,返回结 ...
- DAO设计模式 -- 使用数据库连接类连接MySql数据库并实现添加用户
1. DAO简介 DAO设计模式是属于J2EE数据库层的操作,使用DAO设计模式可以简化大量代码,增强程序的可移植性. 2. DAO各部分详解 DAO设计模式包括5个重要的部分,分别为数据 ...
随机推荐
- Java调用OCR进行图片识别
使用Java语言,通过Tesseract-OCR对图片进行识别. 1.Tesseract-OCR 下载windows版本并安装. 2.程序如下: a.ImageIOHelper类 package OC ...
- Android framework回想(2) sp 和 wp sp对象
用MediaPlayer说明sp的实现.sp是一个模板类,T是RefBase的子类.仅仅要继承于RefBase的类都能够使用sp. binder类也继承RefBase类,binder的实现离不开Ref ...
- C/S模式与B/S
网络程序开发的两种计算模式--C/S模式与B/S模式.两种各有千秋,用于不同场合. C/S适用于专人使用,安全性要求较高的系统: B/S适用于交互性比较频繁的场合,容易被人们所接受,倍受用户和软件开发 ...
- Snail—UI学习之得到某组件的方法
第一种方法:依据传入函数的參数对象的tag属性区分 比方 多个button运行同一个方法,可是不同的方法运行时.里面的逻辑又不一样 那就得加以区分 这时能够用tag来差别 //再新建一个Button ...
- 关于websocket集群中不同服务器的用户间通讯问题
最近将应用部署到集群时遇到一个问题,即用户命中不同的服务器导致的用户间无法进行websocket通讯,在网上搜索到类似问题但都没有具体解决方案. 于是用redis的订阅发布功能解决了该问题,具体流程如 ...
- 百度搜索推出惊雷算法严厉打击刷点击作弊行为-SEO公司分享
百度搜索推出惊雷算法严厉打击刷点击作弊行为 2017年11月20日凌晨,百度搜索引擎发布更新惊雷算法旨在打击刷点击作弊行为. 下面是惊雷算法相关新闻报道: 百度搜索将于11月底推出惊雷算法,严厉打击通 ...
- TX1 flash backup & restore
备份:耗时2.5小时 ./tegraflash.py --bl cboot.bin --applet nvtboot_recovery.bin --chip 0x21 --cmd "read ...
- Windows Power Shell简介
Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能. 它引入了许多非常有用的新概念,从而进一步扩展了您在 W ...
- executing external native build for cmake
进一步调试的方法: 在Android studio下方打开terminal,然后: gradlew build --stacktrace
- 命令行调用dubbo远程服务
命令行调用dubbo远程服务 telnet远程连接到dubbo telnet 127.0.0.1 20880 查看提供服务的接口 dubbo>ls com.test.service.TestIn ...