mysql5.6Linux下安装 卸载 授权

mysql5.6Linux下安装

下载相关地址:链接:https://pan.baidu.com/s/1RorPrEOqpi8uhvj6dEp7mg
提取码:47eu

#关闭防火墙
service iptables stop
#永久关闭:chkconfig iptables off 重启生效:reboot
#创建文件夹上传文件到apps下
mkdir -p /apps
#解压关文件
tar zxvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
cd /apps
#软链接就是:“ln –s 源文件 目标文件”,只会在选定的位置上生成一个文件的镜像,不会占用磁盘空间,类似与windows的快捷方式。
ln -sf /apps/mysql-5.6.31-linux-glibc2.5-x86_64 /usr/local/mysql

groupadd mysql  
useradd mysql -g mysql -p mysql123456 -s /sbin/nologin -M
mkdir /var/run/mysqld -p
mkdir /apps/mysql-5.6.31-linux-glibc2.5-x86_64/data -p
chown -R mysql:mysql /var/run/mysqld

#一起执行start
echo “[client]” > /etc/my.cnf
echo “default-character-set=utf8” >> /etc/my.cnf
echo “socket=/apps/mysql-data/mysql.sock” >> /etc/my.cnf
echo “[mysqld]” >> /etc/my.cnf
echo “datadir=/apps/mysql-data” >> /etc/my.cnf
echo “socket=/apps/mysql-data/mysql.sock” >> /etc/my.cnf
echo “symbolic-links=0” >> /etc/my.cnf
echo “skip-name-resolve” >> /etc/my.cnf
echo “character-set-server=utf8” >> /etc/my.cnf
echo “max_connections=1000” >> /etc/my.cnf
echo “lower_case_table_names=1” >> /etc/my.cnf
echo “[mysqld_safe]” >> /etc/my.cnf
echo “log-error=/var/log/mysqld.log” >> /etc/my.cnf
echo “pid-file=/var/run/mysqld/mysqld.pid” >> /etc/my.cnf
#end

#一起执行start
cd /apps/mysql-5.6.31-linux-glibc2.5-x86_64 &&
chown -R mysql . &&
chgrp -R mysql . &&
#bin/mysqld --initialize --user=mysql &&
scripts/mysql_install_db
–basedir=/apps/mysql-5.6.31-linux-glibc2.5-x86_64
–datadir=/apps/mysql-data --user=mysql &&
chown -R root . &&
chown -R mysql data
#end
cp /apps/mysql-5.6.31-linux-glibc2.5-x86_64/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld start

#Linux下修改Mysql的用户(root)的密码通过登录mysql系统,
mysql -uroot -p(如果出现 #-bash: mysql: command not found 解决方案: ln -s /usr/local/mysql/bin/mysql /usr/bin
Enter password: 【输入原来的密码】 回车(首次登录无密码)如果(
#ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/apps/mysql-data/mysql.sock’ (2)
#先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动
#确定你的mysql.sock是不是在那个位置,
#mysql -u root -p -S /var/lib/mysql/mysql.sock
#试试:service mysqld start
#如果是权限问题,则先改变权限 #chown -R mysql:mysql /apps/mysql-data/mysql.sock)
mysql>use mysql;
mysql> update user set password=passworD(“123456”) where user=‘root’;
开放root:远程连接
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO ‘root’@‘localhost’ IDENTIFIED BY ‘pa44w0rd’ WITH GRANT OPTION;
mysql> flush privileges;

######################### mysql卸载 #############################################################
#1、使用以下命令查看当前安装mysql情况
rpm -qa|grep -i mysql
显示之前安装了:
mysql-libs-5.1.71-1.el6.x86_64

#2、停止mysql服务

service mysqld stop

#3删除之前安装的mysql
rpm -ev mysql-libs-5.1.71-1.el6.x86_64

如果提示依赖包错误,则使用以下命令尝试
error: Failed dependencies:
libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
mysql-libs is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
则使用以下命令尝试
rpm -ev mysql-libs-5.1.71-1.el6.x86_64 --nodeps

如果提示错误:error: %preun(xxxxxx) scriptlet failed, exit status 1
则用以下命令尝试:
rpm -e --noscripts mysql-libs-5.1.71-1.el6.x86_64

#4查找之前老版本mysql的目录、并且删除老版本mysql的文件和库

find / -name mysql
查找结果如下:
/apps/mysql-data/mysql
/apps/mysql-5.6.31-linux-glibc2.5-x86_64/include/mysql
/apps/mysql-5.6.31-linux-glibc2.5-x86_64/bin/mysql
/usr/local/mysql
/var/spool/mail/mysql

删除对应的mysql目录
rm -rf /apps/mysql-data/mysql
rm -rf /apps/mysql-5.6.31-linux-glibc2.5-x86_64/include/mysql
rm -rf /apps/mysql-5.6.31-linux-glibc2.5-x86_64/bin/mysql
rm -rf /usr/local/mysql
rm -rf /var/spool/mail/mysql

注意:卸载后/etc/my.cnf不会删除,需要进行手工删除
rm -rf /apps/mysql-data/
rm -rf /etc/my.cnf

检查是否删除干净
find / -name mysql
无结果,说明已经卸载彻底
4、再次查找机器是否安装mysql,无结果,说明已经卸载彻底
rpm -qa|grep -i mysql

######################### mysq用户授权 #############################################################
#Linux下修改Mysql的用户(root)的密码通过登录mysql系统,
mysql -uroot -p(如果出现 #-bash: mysql: command not found 解决方案: ln -s /usr/local/mysql/bin/mysql /usr/bin
Enter password: 【输入原来的密码】 回车(首次登录无密码)如果(
#ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/apps/mysql-data/mysql.sock’ (2)
#先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动
#确定你的mysql.sock是不是在那个位置,
#mysql -u root -p -S /var/lib/mysql/mysql.sock
#试试:service mysqld start
#如果是权限问题,则先改变权限 #chown -R mysql:mysql /apps/mysql-data/mysql.sock)
mysql>use mysql;
mysql> update user set password=passworD(“123456”) where user=‘root’;
开放root:远程连接
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO ‘root’@‘localhost’ IDENTIFIED BY ‘pa44w0rd’ WITH GRANT OPTION;
mysql> flush privileges;

#增加一个用户mysql密码为mysql,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。
grant select,insert,update,delete on . to mysql@"%" Identified by “mysql”;
grant ALL PRIVILEGES on . to km@"%" Identified by “aaAA11–”;
#新增用户拥有所以权限
GRANT ALL PRIVILEGES ON . TO ‘km’@’%’ IDENTIFIED BY ‘km’

#新建用户并且授权个别表权限:多张执行多条
grant select,insert,update,delete on ln_km.sys_user_mid to mysql@"%" Identified by “mysql”;
#新建用户并且授权莫个库权限
grant select,insert,update,delete on jwyy.* to jwyy_km@"%" Identified by “pa44w0rd”;

Linux下修改Mysql的用户(root)的密码通过登录mysql系统,

mysql -uroot -p #-bash: mysql: command not found ln -s /usr/local/mysql/bin/mysql /usr/bin

Enter password: 【输入原来的密码】
mysql>use mysql;
mysql> update user set password=passworD(“123456”) where user=‘root’;
mysql> flush privileges;

开放root:远程连接
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;

#增加一个用户mysql密码为mysql,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。
grant select,insert,update,delete on . to mysql@"%" Identified by “mysql”;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值