使用工具: VM 15.5.1 Pro 、 centOS7.8(3.10.0) 、 SecureCRT 8.1
一、安装mysql
1.获取mysql-5.6.46.tar.gz安装包
点此获取,密码:xsnq
2.删除老版本mysql的目录
此步骤根据自己的系统版本选择进行,请注意命令是否可以执行。
详细如何卸载mysql点击此处
[root@xsnq ~]# find / -name mysql -exec rm -rf {} \;
完全匹配查找‘mysql’的文件和目录并将查找到的内容删除。
3.安装mysql-5.6.46
以下所有操作将在CRT上完成
3.1 上传mysql-5.6.46
[root@xsnq ~]# yum -y install lrzsz //下载上传工具
[root@xsnq ~]# rz //对弹窗操作,选择安装包,Add-->Ok
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring mysql-5.6.46.tar.gz...
100% 31635 KB 31635 KB/sec 00:00:01 0 Errors
[root@xsnq ~]# ls //查看是否上传成功
anaconda-ks.cfg mysql-5.6.46.tar.gz
3.2 安装
//安装依赖
[root@xsnq ~]# yum -y install bison cmake ncurses-devel openssl-devel perl-Data-Dumper gcc gcc-c++
//解压
[root@xsnq ~]# tar -zxvf mysql-5.6.46.tar.gz
[root@xsnq ~]# cd mysql-5.6.46/
//配置
[root@xsnq mysql-5.6.46]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
//编译&&安装
[root@xsnq mysql-5.6.46]# make -j8 && make install
[root@xsnq mysql-5.6.46]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib
[root@xsnq mysql-5.6.46]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@xsnq mysql-5.6.46]# useradd -M -s /sbin/nologin mysql
[root@xsnq mysql-5.6.46]# chown -R mysql:mysql /usr/local/mysql/
[root@xsnq mysql-5.6.46]# cd support-files/
[root@xsnq support-files]# cp my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@xsnq support-files]# cp mysql.server /etc/init.d/mysqld
//修改配置文件
[root@xsnq support-files]# vi /etc/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/usr/local/mysql/data
//赋予service对mysqld的执行权限
[root@xsnq support-files]# chmod +x /etc/init.d/mysqld
//初始化数据库
[root@xsnq support-files]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
//启动MySQL
[root@xsnq ~]# cd
[root@xsnq ~]# service mysqld start 或 /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
//登录mysql
[root@xsnq ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.46 Source distribution
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
//设置登录用户密码
mysql> use mysql; //使用mysql库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password('123456') where user='root'; //设置用户为root,密码为123456
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> Ctrl-C -- exit! //退出
[root@xsnq ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@xsnq ~]# mysql -uroot -p //登录或mysql -uroot -p123456(会暴露密码)
Enter password: //密文不显示密码
用户:root 密码:123456
启动mysql:service mysqld start 或 /etc/init.d/mysqld start
关闭mysql:service mysqld stop 或 /etc/init.d/mysqld stop
重启mysql:service mysqld restart 或 /etc/init.d/mysqld restart
查看mysql进程:ps -ef | grep mysql
查看mysql端口:netstat -naltp | grep mysqld(默认端口为3306)
二、卸载mysql
2.1
安装时因为使用了–prefix这个命令,所以这里把指定的文件给删除了就行了
[root@localhost ~]# rm -rf /usr/local/mysql/ //安装时的位置
//到这一步,差不多就可以了。
[root@localhost ~]# rm -rf mysql-5.6.46 //删除解压包
[root@xsnq ~]# find / -name mysql //再找出一些残留文件
rm -rf 再删除一些查找出来的残留文件,再反推回去删除ln的文件和mysql用户。
参考文献
https://blog.csdn.net/weixin_45074532/article/details/106472364
https://blog.csdn.net/tjcyjd/article/details/52189182
本文出现任何错误,请留言批评指正。
文章内容如涉及版权问题,可留言至本文章或私信删除。