Linux安装mysql登录问题-适用root强制登录
安装mysql5姿势是要先安装带有可用的mysql5系列社区版资源的rpm包
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
这个时候查看当前可用的mysql安装资源:
yum repolist enabled | grep "mysql.*-community.*"
直接使用yum的方式安装MySQL了
yum -y install mysql-community-server
加入开机启动
systemctl enable mysqld
systemctl start mysqld
重置密码
mysql_secure_installation
安装mysql后,常规方法登录出现错误提示。直接:
/etc/my.cnf添加以下加粗的三句:
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M skip-grant-tables datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock port=3306 explicit_defaults_for_timestamp=true # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
启动mysqld:【强制启动】
mysqld --user=root
创建hfishdb数据库
create database hfishdb;
最后,更改密码这些。
启动另一个窗口,然后:
步骤 1):输入命令mysql -uroot
步骤 2):输入use mysql;
命令连接权限数据库。
步骤 3):输入命令update mysql.user set authentication_string=password('新密码') where user='用户名' and Host ='localhost';
设置新密码。
步骤 4):输入 flush privileges;
命令刷新权限。
步骤 5):输入quit;
命令退出 MySQL 重新登录,此时密码已经修改为刚才输入的新密码了。
重要的是,最后应该在/etc/my.cnf中加注释:
#skip-grant-tables
最后,根据需求设定IP访问权限:
grant all privileges on *.* to 'root'@'特定IP地址' identified by '密码' with grant option; flush privileges; 命令刷新权限