乱七八糟的shell脚本大集合

#!/bin/bash
mysql_root_pwd=$(date +%s | sha256sum | base64 | head -c ; echo)
mysql_cnf_path=$
export mysql_passwd=$mysql_root_pwd
echo "------------------------------Stoping mysql-----------------------------------------"
/etc/init.d/mysql stop
sed -i '/\[mysqld\]/askip-grant-tables' $mysql_cnf_path
/etc/init.d/mysql start
echo "-------------------------------Changing pasword--------------------------------------"
printf "mysql password is %s" "$mysql_root_pwd" > /root/mysqlpassword
mysql -uroot mysql << EOF
use mysql;
update user set password = Password('$mysql_passwd') where User = 'root';
commit;
flush privileges;
EOF if [ $? -eq ]; then
echo "------------Password reset succesfully. Now restarting mysqld softly-------------------"
sed -i '/skip-grant-tables/d' /etc/my.cnf
/etc/init.d/mysql restart
echo "--------------------------Password set success----------------------------------------"
else
mysql -uroot mysql << EOF
use mysql;
update user set authentication_string = Password('$mysql_passwd') where User = 'root';
commit;
flush privileges;
EOF
if [ $? -eq ]; then
echo "------------Password reset succesfully. Now restarting mysqld softly-------------------"
sed -i '/skip-grant-tables/d' $mysql_cnf_path
/etc/init.d/mysql restart
echo "--------------------------Password set success----------------------------------------"
else
echo "--------------------------Password set failed----------------------------------------"
fi
fi

linux一键修改mysql密码脚本的更多相关文章

  1. Linux系统修改Mysql密码

    一.拥有原来的myql的root的密码: 方法一: 在mysql系统外,使用mysqladmin mysqladmin -u root -p password "test123" ...

  2. (linux)修改MySQL密码方法

    1,在/etc/my.cnf末尾  加入skip-grant-tables,保存,跳过身份验证. 2,重启MySql,使刚才修改的配置生效. 3,终端输入mysql,然后再输入use mysql; 4 ...

  3. Linux下修改Mysql密码的三种方式

    前言 有时我们会忘记Mysql的密码,或者想改一个密码,以下将对这两种情况修改密码的三种解决方法做个总结 本文都以用户为 root 为例 一.拥有原来的myql的root的密码 方法一: 在mysql ...

  4. Linux下修改mysql密码

    # /etc/init.d/mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysq ...

  5. linux批量修改root密码脚本

    转至:https://blog.csdn.net/onionm/article/details/100514892?utm_medium=distribute.pc_relevant_download ...

  6. kali linux 2018.2 mysql密码修改后无效,外部无法连接问题。

    kali linux 2018.2 mysql密码修改后无效,外部无法连接问题 Kali Linux 2018.2 默认MySQL数据库是mariadb,可能和MySQL有些细微的变化,只需要做如下处 ...

  7. linux下修改mysql登录密码

    一.修改mysql密码 1.停止服务      /etc/init.d/mysqld stop   2.以不检查权限的方式启动     /etc/init.d/mysqld --skip-grant- ...

  8. Linux下忘记MySQL密码的解决方法和输入mysqld_safe --skip-grant-tables &后无法进入MySQL的解决方法

    在Linux下忘记MySQL密码后我们可以通过一个mysql的参数--skip-grant-tables &轻松解决这个问题 亲测在CentOS有效 其中 --skip-grant-table ...

  9. Navicat Premium 修改MySQL密码(忘记密码的情况下)

    Navicat Premium 修改MySQL密码 1,首先,Navicat Premium还能够连接MySQL. 2,选择数据库,右键单击,选择“命令行模式...”,下图示例 3,打开命令行模式, ...

随机推荐

  1. Storm简介及使用

    一.Storm概述 网址:http://storm.apache.org/ Apache Storm是一个免费的开源分布式实时计算系统.Storm可以轻松可靠地处理无限数据流,实现Hadoop对批处理 ...

  2. pycharm修改选中字体颜色

    File->Setting->Editor->Color Scheme->General Scheme:Monokai 在方框内: Editor->Section Bac ...

  3. python学习笔记(二十七)多线程与多进程

    线程是程序里面的最小执行单元. 进程是资源的集合. 线程是包含在一个进程里面,一个进程可以有多个线程,一个进程里面默认有一个主线程.由主线程去启动子线程. 1.多线程 import threading ...

  4. python16_day20【Django_继续抽屉项目】

    一.djangoAdmin和表结构 1.项目名称 python manage startapp web # 前端页面 python manage startapp repository   # 只是数 ...

  5. SVN遇到的问题和解决方法(后期还会继续更新)

    1,smartsvn客户端(version客户端类似),一些.a文件无法识别,也就无法提交到svn! 解决办法如下: 在smartsvn客户端下面view->Ignored Files 勾选上就 ...

  6. python阳历转阴历,阴历转阳历

    #!/usr/bin/env python # coding:utf8 # author:Z time:2019/1/16 import sxtwl # 日历中文索引 ymc = [u"十一 ...

  7. xphrof出现502问题

    This is an xhprof bug and not a devel bug, but I thought I'd throw the workaround up here in case pe ...

  8. Django 分页查询并返回jsons数据,中文乱码解决方法

    Django 分页查询并返回jsons数据,中文乱码解决方法 一.引子 Django 分页查询并返回 json ,需要将返回的 queryset 序列化, demo 如下: # coding=UTF- ...

  9. linux_rpm命令

    rpm 常用命令 1.安装一个包 # rpm -ivh 文件名 2.升级一个包 # rpm -Uvh文件名 3.移走一个包 # rpm -e文件名 4.安装参数 --force 即使覆盖属于其它包的文 ...

  10. java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' 异常处理,及MySQL数据库编码设置

    java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,C ...