第一步:查看当前系统是否自带MySQL数据库
[root@MySqlServer ~]# rpm -qa | grep mysql
mysql-libs-5.1.66-2.el6_3.i686
[root@MySqlServer ~]#
说明:执行 rpm -qa | grep mysql 命令来查看当然系统是否自带有MySQL数据库,若有,则会显示MySQL软件名称。
第二步:卸载自带的MySQL数据库
[root@MySqlServer ~]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.i686 [root@MySqlServer ~]#
说明:命令 rpm -e --nodeps [要卸载的软件名] 用于卸载软件。
第三步:安装从网上下载文件的wget命令
[root@master ~]# yum -y install wget
wget 是一个从网络上自动下载文件的自由工具
第四步:下载mysql的repo源
[root@master ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
如果下载成功,它会在/root目录下有一个mysql-community-release-el7-5.noarch.rpm文件
第五步:将当前目录转到 /root之下
第六步:安装mysql-community-release-el7-5.noarch.rpm包
[root@master ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
第七步:查看下,意思是看安装mysql有几个源
[root@master ~]# ls -1 /etc/yum.repos.d/mysql-community*
/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo
会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
第八步:安装mysql
[root@master ~]# yum install mysql-server
第九步:
6)启动mysql服务
[root@MySqlServer mysql]# service mysql start
Starting MySQL. [ OK ]
[root@MySqlServer mysql]#
7)连接数据库
[root@MySqlServer mysql]# mysql -uroot -p
Enter password:
结果是密码错误,需要重置密码
[root@VM_0_11_centos /]# grep 'temporary password' /var/log/mysqld.log
2018-08-10T09:50:14.984060Z 1 [Note] A temporary password is generated for root@localhost: jK_e>o6siRFg
[root@VM_0_11_centos /]# mysql -uroot -p
Enter password: 输入上面查询到的密码【jK_e>o6siRFg】
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23
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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password for root@localhost = password('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set password for root@localhost = password('Root@123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
完成!
启动mysql:
service mysqld start
停止mysql:
service mysqld stop
由于软件安装的地方不止一个地方,所有先说查看文件安装的所有路径(地址)。
这里以mysql为例。比如说我安装了mysql,但是不知道文件都安装在哪些地方、放在哪些文件夹里,可以用下面的命令查看所有的文件路径 在终端输入:
whereis mysql
回车,如果你安装好了mysql,就会显示文件安装的地址,例如我的显示(安装地址可能会不同)
[root@localhost ~]# whereis mysql mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
如果你只要查询文件的运行文件所在地址,直接用下面的命令就可以了(还是以mysql为例):
which mysql
终端显示:
[root@localhost ~]# which mysql
/usr/bin/mysql