mysql卸载和安装

卸载:

1.停止服务,查询服务命令:

[root@1dot1dot1dot1 ~]# service mysql status
MySQL running (18003)                                      [  OK  ]

停止服务命令:

[root@1dot1dot1dot1 ~]# service mysql stop
Shutting down MySQL.                                       [  OK  ]

2.查找mysql相关组件,命令如下:

[root@1dot1dot1dot1 ~]# rpm -qa | grep mysql
mysql-devel-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64


可以看到安装了3个组件

3.收集mysql相关文件夹信息,命令如下:

[root@1dot1dot1dot1 ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /opt/mysql5.6.41/bin/mysql /usr/share/man/man1/mysql.1.gz

4.使用find查看mysql数据库相关文件,命令如下:

[root@1dot1dot1dot1 ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/var/spool/mail/mysql
/usr/include/mysql
/usr/share/mysql
/usr/local/openldap-2.4.46/servers/slapd/back-sql/rdbms_depend/mysql
/usr/local/share/kea/scripts/mysql
/usr/bin/mysql
/usr/lib64/mysql
/home/ruby/ruby-dbi/lib/dbd/mysql
/home/ruby/ruby-dbi/test/dbd/mysql
/home/mysql-5.6.41/include/mysql
/home/mysql-5.6.41/client/mysql
/home/mysql-5.6.41/storage/ndb/test/crund/tws/tws_java/src/com/mysql
/home/mysql-5.6.41/storage/ndb/test/crund/src/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-openjpa/src/test/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-openjpa/src/main/resources/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-jpatest/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-core/src/main/resources/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-jdbc/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-jdbc/src/main/resources/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-jdbc/src/main/antlr3/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-tie/src/test/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-tie/src/main/resources/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-bindings/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-bindings/src/main/resources/com/mysql
/home/mysql-5.6.41/storage/ndb/clusterj/clusterj-api/src/main/java/com/mysql
/home/mysql-5.6.41/storage/ndb/src/ndbjtie/jtie/com/mysql
/home/mysql-5.6.41/storage/ndb/src/ndbjtie/com/mysql
/home/mysql-5.6.41/storage/ndb/src/ndbjtie/com/mysql/ndbjtie/mysql
/home/mysql-5.6.41/storage/ndb/src/ndbjtie/mysql
/opt/mysql5.6.41/include/mysql
/opt/mysql5.6.41/bin/mysql
/etc/rc.d/init.d/mysql


5.卸载mysql各类组件,对应步骤2中查找到的组件,命令如下:

[root@1dot1dot1dot1 ~]# rpm -ev mysql-devel-5.1.73-8.el6_8.x86_64
[root@1dot1dot1dot1 ~]# rpm -ev mysql-libs-5.1.73-8.el6_8.x86_64


6.卸载mysql相关文件,对应步骤3,4中找到的文件,直接rm -rf

7.删除用户和组,如下:

[root@1dot1dot1dot1 ~]# userdel mysql
[root@1dot1dot1dot1 ~]# groupdel mysql

安装:

官网下载地址:https://dev.mysql.com/downloads/mysql/

源码安装需要先安装cmake,这里直接用mysql-5.6.41-linux-glibc2.12-x86_64.tar

1.解压,创建组和用户,如下:

[root@1dot1dot1dot1 home]# groupadd mysql
[root@1dot1dot1dot1 home]# useradd -r -g mysql mysql

2.可以看/etc/my.cnf文件,描述了data目录、错误日志路径等信息,若没有此文件,可以等待安装之后使用默认的,或者手动添加,如下:

[root@1dot1dot1dot1 home]# cat /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


3.修改目录权限为mysql,如下:

[root@1dot1dot1dot1 mysql-5.6.41]# chown -R mysql:mysql .

注意最后有一个点

4.初始化数据库,命令如下:

[root@1dot1dot1dot1 mysql-5.6.41]# ./scripts/mysql_install_db --user=mysql --basedir=/home/mysql-5.6.41 --datadir=/home/mysql-5.6.41/data
Installing MySQL system tables...2018-09-13 12:05:56 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-13 12:05:56 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-09-13 12:05:56 0 [Note] /home/mysql-5.6.41/bin/mysqld (mysqld 5.6.41) starting as process 19646 ...
2018-09-13 12:05:56 19646 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-09-13 12:05:56 19646 [Note] InnoDB: The InnoDB memory heap is disabled
2018-09-13 12:05:56 19646 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-09-13 12:05:56 19646 [Note] InnoDB: Memory barrier is not used
2018-09-13 12:05:56 19646 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-09-13 12:05:56 19646 [Note] InnoDB: Using Linux native AIO
2018-09-13 12:05:56 19646 [Note] InnoDB: Using CPU crc32 instructions
2018-09-13 12:05:56 19646 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-09-13 12:05:56 19646 [Note] InnoDB: Completed initialization of buffer pool
2018-09-13 12:05:56 19646 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-09-13 12:05:56 19646 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-09-13 12:05:56 19646 [Note] InnoDB: Database physically writes the file full: wait...
2018-09-13 12:05:56 19646 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-09-13 12:05:56 19646 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-09-13 12:05:57 19646 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-09-13 12:05:57 19646 [Warning] InnoDB: New log files created, LSN=45781
2018-09-13 12:05:57 19646 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-09-13 12:05:57 19646 [Note] InnoDB: Doublewrite buffer created
2018-09-13 12:05:57 19646 [Note] InnoDB: 128 rollback segment(s) are active.
2018-09-13 12:05:57 19646 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-13 12:05:57 19646 [Note] InnoDB: Foreign key constraint system tables created
2018-09-13 12:05:57 19646 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-09-13 12:05:57 19646 [Note] InnoDB: Tablespace and datafile system tables created.
2018-09-13 12:05:57 19646 [Note] InnoDB: Waiting for purge to start
2018-09-13 12:05:57 19646 [Note] InnoDB: 5.6.41 started; log sequence number 0
2018-09-13 12:05:57 19646 [Note] Binlog end
2018-09-13 12:05:57 19646 [Note] InnoDB: FTS optimize thread exiting.
2018-09-13 12:05:57 19646 [Note] InnoDB: Starting shutdown...
2018-09-13 12:05:58 19646 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2018-09-13 12:05:58 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-13 12:05:58 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-09-13 12:05:58 0 [Note] /home/mysql-5.6.41/bin/mysqld (mysqld 5.6.41) starting as process 19689 ...
2018-09-13 12:05:58 19689 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-09-13 12:05:58 19689 [Note] InnoDB: The InnoDB memory heap is disabled
2018-09-13 12:05:58 19689 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-09-13 12:05:58 19689 [Note] InnoDB: Memory barrier is not used
2018-09-13 12:05:58 19689 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-09-13 12:05:58 19689 [Note] InnoDB: Using Linux native AIO
2018-09-13 12:05:58 19689 [Note] InnoDB: Using CPU crc32 instructions
2018-09-13 12:05:58 19689 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-09-13 12:05:58 19689 [Note] InnoDB: Completed initialization of buffer pool
2018-09-13 12:05:58 19689 [Note] InnoDB: Highest supported file format is Barracuda.
2018-09-13 12:05:59 19689 [Note] InnoDB: 128 rollback segment(s) are active.
2018-09-13 12:05:59 19689 [Note] InnoDB: Waiting for purge to start
2018-09-13 12:05:59 19689 [Note] InnoDB: 5.6.41 started; log sequence number 1625977
2018-09-13 12:05:59 19689 [Note] Binlog end
2018-09-13 12:05:59 19689 [Note] InnoDB: FTS optimize thread exiting.
2018-09-13 12:05:59 19689 [Note] InnoDB: Starting shutdown...
2018-09-13 12:06:00 19689 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /home/mysql-5.6.41/bin/mysqladmin -u root password 'new-password'
  /home/mysql-5.6.41/bin/mysqladmin -u root -h 1dot1dot1dot1.cloudflare-dns.com password 'new-password'

Alternatively you can run:

  /home/mysql-5.6.41/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /home/mysql-5.6.41/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /home/mysql-5.6.41/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server


5.添加启动服务,如下:

[root@1dot1dot1dot1 mysql-5.6.41]# cp support-files/mysql.server /etc/init.d/mysql


6.启动mysql服务

[root@1dot1dot1dot1 ~]# service mysql start
Starting MySQL.Logging to '/home/mysql-5.6.41/data/1dot1dot1dot1.cloudflare-dns.com.err'.
......................................................     [  OK  ]

7.查询mysql状态,已经启动:

[root@1dot1dot1dot1 mysql-5.6.41]# service mysql status
MySQL running (20245)                                      [  OK  ]

8.设置root用户的密码:

[root@1dot1dot1dot1 mysql]# /usr/local/mysql/bin/mysqladmin -u root password '123456'
Warning: Using a password on the command line interface can be insecure.


可能出现warning,从5.6版本用这样的明文方式不安全,可以在my.cnf中增加如下字段:

[mysqld]

user=root
password=root

9.连接到mysql,命令:

[root@1dot1dot1dot1 mysql]# mysql -u root -p
-bash: /usr/bin/mysql: No such file or directory


出现这个错误的原因是默认在/usr/bin下查找,需要建立软连接,如下:

[root@1dot1dot1dot1 mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@1dot1dot1dot1 mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 


到这里,连接成功

可能遇到的其他问题:

1.

[root@1dot1dot1dot1 ~]# service mysql start
/etc/init.d/mysql: line 244: my_print_defaults: command not found

解决:cp bin/my_print_defaults /usr/bin

2.

[root@1dot1dot1dot1 mysql-5.6.41]# service mysql start
/etc/init.d/mysql: line 264: cd: /usr/local/mysql: No such file or directory

解决:服务初始化文件中默认是/usr/local/mysql,修改启动文件指定安装路径即可

3.

[root@1dot1dot1dot1 mysql-5.6.41]# service mysql start
Starting MySQL.180913 12:17:12 mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.

解决:删除/etc/my.cnf

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
卸载 MySQL,你可以按照以下步骤进行操作: 1. 停止 MySQL服务。你可以在命令行中运行以下命令来停止 MySQL服务: - 对于 Windows 系统:`net stop mysql` - 对于 macOS 或 Linux 系统:`sudo service mysql stop` 2. 卸载 MySQL 软件。具体步骤取决于你的操作系统: - 对于 Windows 系统:通过控制面板的 "程序和功能"选项卸载 MySQL。 - 对于 macOS 系统:删除 MySQL 的应用程序文件夹。 - 对于 Linux 系统:使用适当的包管理器(例如 apt、yum 或 dnf)来卸载 MySQL。 3. 删除 MySQL 数据和配置文件。这些文件通常位于以下位置: - 对于 Windows 系统:`C:\Program Files\MySQL` 和 `C:\ProgramData\MySQL`。 - 对于 macOS 系统:`/usr/local/mysql` 和 `/etc/my.cnf`。 - 对于 Linux 系统:`/var/lib/mysql` 和 `/etc/my.cnf`。 注意:在执行任何卸载操作之前,请确保备份了重要的数据库文件和配置文件。 要安装 MySQL,你可以按照以下步骤进行操作: 1. 下载 MySQL 安装程序。你可以从 MySQL 官方网站(https://dev.mysql.com/downloads/)下载适用于你的操作系统的安装程序。 2. 运行安装程序。根据提示进行安装,可以选择自定义安装选项,例如安装路径、端口号等。 3. 配置 MySQL。在安装过程中,你将被要求设置 root 用户的密码和其他一些配置选项。 4. 启动 MySQL服务。根据你的操作系统,可以在命令行中运行以下命令来启动 MySQL服务: - 对于 Windows 系统:`net start mysql` - 对于 macOS 或 Linux 系统:`sudo service mysql start` 完成以上步骤后,你应该成功地卸载并重新安装MySQL 数据库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值