查看初始密码
cat /root/.mysql_secret
##Linux下彻底卸载mysql详解
一、使用以下命令查看当前安装mysql情况,查找以前是否装有mysql
rpm -qa|grep -i mysql
可以看到如下图的所示:
显示之前安装了:
MySQL-client-5.5.25a-1.rhel5
MySQL-server-5.5.25a-1.rhel5
2、停止mysql服务、删除之前安装的mysql
删除命令:rpm -e –nodeps 包名
rpm -ev MySQL-client-5.5.25a-1.rhel5
rpm -ev MySQL-server-5.5.25a-1.rhel5
如果提示依赖包错误,则使用以下命令尝试
rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps
如果提示错误:error: %preun(xxxxxx) scriptlet failed, exit status 1
则用以下命令尝试:
rpm -e --noscripts MySQL-client-5.5.25a-1.rhel5
3、查找之前老版本mysql的目录、并且删除老版本mysql的文件和库
find / -name mysql
查找结果如下:
find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
删除对应的mysql目录
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
具体的步骤如图:查找目录并删除
注意:卸载后/etc/my.cnf不会删除,需要进行手工删除
rm -rf /etc/my.cnf
4、再次查找机器是否安装mysql
rpm -qa|grep -i mysql
linux上安装mysql5.7
1、下载tar包,这里使用wget从官网下载
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
2、将mysql安装到/usr/local/mysql下
解压
tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
移动
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
重命名
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
3、新建data目录
mkdir /usr/local/mysql/data
4、新建mysql用户、mysql用户组
groupadd mysql和useradd -r -g mysql mysql
mysql用户组
groupadd mysql
mysql用户
useradd mysql -g mysql
5、将/usr/local/mysql的所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql
6、配置
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
如果出现以下错误:
复制代码
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
– server log begin –
– server log end –
复制代码
则使用以下命令:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
如果出现以下错误:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
则执行以下命令:
yum -y install numactl
yum install -y libaio
yum install libncurses*
场景:
在CentOS7.6系统下安装Mysql5.7时,初始化的时候报错:
mysqld: error while loading shared libraries: libaio.so.1:cannot open shared object file: No such file or directory
解决:
因为是新的系统,并没有安装所需要的依赖包
完成后继续安装:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
编辑/etc/my.cnf
复制代码
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
取消密码验证
skip-grant-tables
symbolic-links=0
skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
复制代码
7、开启服务
将mysql加入服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
开机自启
chkconfig mysql on
开启
service mysql start
8、设置密码
登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)
/usr/local/mysql/bin/mysql -u root -p
操作mysql数据库
use mysql;
如果报错
在连接mysql执行语句时报错:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
执行语句:
alter user 'root'@localhost identified by 'root';
这样就可以了。
修改密码
update user set authentication_string=password('你的密码') where user='root';
update mysql.user set authentication_string='123456789' where user='root';
flush privileges;
exit;
9、将/etc/my.cnf中的skip-grant-tables删除
解决MySQL修改密码:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option
1.找不到初始密码可以在my.ini中[mysqld] 添加:
skip-grant-tables
2.修改MySQL数据库配置文件无密码登录后,修改密码报错:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
3.先执行:
flush privileges;
4.再执行修改密码命令,可以了:
set password for root@localhost=password('你的密码');
10、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)
/usr/local/mysql/bin/mysql -u root -p
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘修改后的密码’;
exit;
11、允许远程连接
/usr/local/mysql/bin/mysql -u root -p
use mysql;
update user set user.Host=‘%’ where user.User=‘root’;
flush privileges;
eixt;
12、添加快捷方式
ln -s /usr/local/mysql/bin/mysql /usr/bin
13.你想myuser使用mypassword从任何主机连接到mysql服务器的话。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;