mysql的安装

一、yum源格式安装mysql

1、将下载的yum包上传到linux上:

[root@localhost ~]# ls
mysql-community-release-el6-5.noarch.rpm 

2、列出rpm包中文件(查看哪些内容):

[root@localhost ~]# rpm -qpl mysql-community-release-el6-5.noarch.rpm 
/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
/etc/yum.repos.d/mysql-community-source.repo
/etc/yum.repos.d/mysql-community.repo

3、安装rpm包(自动配置好yum源):

[root@localhost ~]# rpm -ivh mysql-community-release-el6-5.noarch.rpm 
Preparing... ########################################### [100%]
1:mysql-community-release########################################### [100%]

4、安装mysql:

[root@localhost ~]# yum install mysql-community-server.x86_64 -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Existing lock /var/run/yum.pid: another copy is running as pid 2460.
Another app is currently holding the yum lock; waiting for it to exit...

  Verifying  : mysql-community-libs-5.6.29-2.el6.x86_64                                                                                                                                    5/8 
  Verifying  : 2:postfix-2.6.6-6.el6_7.1.x86_64                                                                                                                                            6/8 
  Verifying  : 2:postfix-2.6.6-2.2.el6_1.x86_64                                                                                                                                            7/8 
  Verifying  : mysql-libs-5.1.71-1.el6.x86_64                                                                                                                                              8/8 
Installed:
  mysql-community-libs.x86_64 0:5.6.29-2.el6                  mysql-community-libs-compat.x86_64 0:5.6.29-2.el6                  mysql-community-server.x86_64 0:5.6.29-2.el6             
Dependency Installed:
  mysql-community-client.x86_64 0:5.6.29-2.el6                                                   mysql-community-common.x86_64 0:5.6.29-2.el6                                            
Dependency Updated:
  postfix.x86_64 2:2.6.6-6.el6_7.1                                                                                                                                                        
Replaced:
  mysql-libs.x86_64 0:5.1.71-1.el6                                                                                                                                                             
Complete!

5、是否安装了mysql:

[root@localhost ~]# rpm -qa | grep mysql
mysql-community-libs-5.6.29-2.el6.x86_64
mysql-community-server-5.6.29-2.el6.x86_64
mysql-community-client-5.6.29-2.el6.x86_64
mysql-community-libs-compat-5.6.29-2.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-community-common-5.6.29-2.el6.x86_64

6、接下来是初始化数据库:

[root@localhost ~]# mysql_install_db --datadir=/var/lib/mysql/
Installing MySQL system tables...2016-03-15 11:00:50 0 [Warning] TIMESTAMP wi

7、更改数据库目录权限并启动mysql:

[root@localhost ~]# chown -R mysql:mysql /var/lib/mysql/
[root@localhost ~]# ll -h /var/lib/mysql/
总用量 109M
-rw-rw----. 1 mysql mysql  12M 3月  15 11:00 ibdata1
-rw-rw----. 1 mysql mysql  48M 3月  15 11:00 ib_logfile0
-rw-rw----. 1 mysql mysql  48M 3月  15 11:00 ib_logfile1
drwx------. 2 mysql mysql 4.0K 3月  15 11:00 mysql
drwx------. 2 mysql mysql 4.0K 3月  15 11:00 performance_schema
[root@localhost ~]# /etc/init.d/mysqld start
正在启动 mysqld:                                          [确定]

8、登录mysql并修改密码:

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> update mysql.user set password=password("123456")where user='root';
Query OK, 3 rows affected (0.11 sec)
Rows matched: 4 Changed: 3 Warnings: 0

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.04 sec)

  

二、RPM方式安装mysql:

1.将下载好的文件上传到Linux下:

[root@localhost Downloads]# ls
MySQL-5.6.16-1.el6.x86_64.rpm-bundle.tar

2、解压tar文件:

[root@localhost Downloads]# tar -xf MySQL-5.6.16-1.el6.x86_64.rpm-bundle.tar

[root@localhost Downloads]# ls
MySQL-client-5.6.16-1.el6.x86_64.rpm
MySQL-devel-5.6.16-1.el6.x86_64.rpm
MySQL-embedded-5.6.16-1.el6.x86_64.rpm
MySQL-server-5.6.16-1.el6.x86_64.rpm
MySQL-shared-5.6.16-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.16-1.el6.x86_64.rpm
MySQL-test-5.6.16-1.el6.x86_64.rpm

3、安装rpm文件:

[root@localhost Downloads]# rpm -Uvh MySQL-*
Preparing... ########################################### [100%]
1:MySQL-devel ########################################### [ 14%]
2:MySQL-client ########################################### [ 29%]
3:MySQL-test ########################################### [ 43%]
4:MySQL-embedded ########################################### [ 57%]
5:MySQL-shared-compat ########################################### [ 71%]
6:MySQL-shared ########################################### [ 86%]
7:MySQL-server ########################################### [100%]

4、启动mysql服务:

[root@localhost mysql]# /etc/init.d/mysql start
Starting MySQL........ [ OK ]

 

转载于:https://www.cnblogs.com/1021lynn/p/5262325.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐