设为首页 收藏本站
查看: 1248|回复: 0

[经验分享] Centos6.5安装MySql

[复制链接]

尚未签到

发表于 2018-4-26 10:01:36 | 显示全部楼层 |阅读模式
  安装MySql方法有多种方式,如下图:
序号MySql安装方式特点说明
1yum/rpm包安装特点是简单、速度快,但是没法定制安装,入门新手常用这种方式
2二进制安装解压软件,简单配置后就可以使用,不用安装,速度较快,专业DNA喜欢这种方式。软件名如:mysql-5.5.32-linux2.6_x86_64.tar.gz
3源码编译安装特点是可以定制安装,但是安装时间长,例如:字符集安装路径,等等。软件名称如:mysql-5.5.32.tar.gz
4源码软件结合yum/rpm安装把源码软件制作成符合要求的rpm,放到yum仓库里,然后通过yum来安装。结合了上面1和3的优点,即安装快速,可做生意定制参数,但是安装者也需要具有更深能力
  下面演示yum和编译安装:
  一、yum安装
  1、关闭iptables
[root@mysql ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@mysql ~]# /etc/init.d/iptables stop
[root@mysql ~]# chkconfig iptables off  2、关闭SELinux
[root@mysql ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@mysql ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@mysql ~]# setenforce 0
[root@mysql ~]# getenforce
Permissive  3、安装mysql
[root@mysql ~]# yum -y install mysql mysql-server mysql-devel
Loaded plugins: fastestmirror, security
base                                                     | 3.7 kB     00:00     
base/primary_db                                          | 4.6 MB     00:30     
extras                                                   | 3.4 kB     00:00     
extras/primary_db                                        |  37 kB     00:00     
updates                                                  | 3.4 kB     00:00     
updates/primary_db                                       | 5.2 MB     00:43
...略
[root@mysql ~]# chkconfig mysqld on                                 
#开机启动
[root@mysql ~]# chkconfig --list | grep mysqld
#查询是否开机启动
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@mysql ~]# service mysqld start
#启动服务
Starting mysqld:                                           [  OK  ]  
[root@mysql ~]# mysql                                                
#进入mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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> CREATE DATABASE wordpress;
#创建一个名称为wordpress的数据库
Query OK, 1 row affected (0.00 sec)
mysql> select user,host,password from mysql.user;                    
#查询用户等信息
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |          |
| root | mysql     |          |
| root | 127.0.0.1 |          |
|      | localhost |          |
|      | mysql     |          |
+------+-----------+----------+
5 rows in set (0.00 sec)
mysql> set password for root@localhost=password('root');
#查询用户的密码,都为空,用上面的命令设置root的密码为root
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;                  
#再次查询发现password下面已有密码信息
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | mysql     |                                           |
| root | 127.0.0.1 |                                           |
|      | localhost |                                           |
|      | mysql     |                                           |
+------+-----------+-------------------------------------------+
5 rows in set (0.00 sec)
mysql> exit
Bye
[root@mysql ~]#
[root@mysql ~]# mysql -u root -p                                    
#用新密码登录
Enter password:                                                     
#填写密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
...略
mysql> exit
[root@mysql ~]#
[root@mysql ~]# cat /etc/my.cnf
#/etc/my.cnf是mysql的主配置文件
[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
[root@mysql ~]#
[root@mysql ~]# ls -l /var/lib/mysql/
#mysql数据库的数据库文件存放位置
total 20492
-rw-rw----. 1 mysql mysql 10485760 May 16 22:30 ibdata1
-rw-rw----. 1 mysql mysql  5242880 May 16 22:30 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 May 16 22:30 ib_logfile1
drwx------. 2 mysql mysql     4096 May 16 22:30 mysql
srwxrwxrwx. 1 mysql mysql        0 May 16 22:30 mysql.sock
drwx------. 2 mysql mysql     4096 May 16 22:30 test
drwx------. 2 mysql mysql     4096 May 16 22:33 wordpress
[root@mysql ~]#
[root@mysql ~]# ls /var/log/
#日志文件存放位置
anaconda.ifcfg.log    anaconda.yum.log  dmesg       mysqld.log  tallylog
anaconda.log          audit             dmesg.old   ntpstats    wtmp
anaconda.program.log  boot.log          dracut.log  prelink     yum.log
anaconda.storage.log  btmp              lastlog     sa
anaconda.syslog       ConsoleKit        maillog     secure
anaconda.xlog         cron              messages    spooler
[root@mysql ~]#
[root@mysql ~]# netstat -lntup|grep 3306
#查看mysql端口侦听状态
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2053/mysqld
[root@mysql ~]#  MySql密码忘记后重新设置:
#多次输入密码均不对
[root@bogon ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# /application/mysql//bin/mysqladmin -u root password '789@!@#'
#把root的mysql登录密码设置为789@!@#
[root@bogon ~]# mysql -u root -p
#输入密码789@!@#,进入mysql
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.32 Source distribution
Copyright (c) 2000, 2013, 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; //查看系统已存在的数据库
  use databasesname;   //选择需要使用的数据库
  drop database databasename; //删除选定的数据库
  exit    //退出数据库的连接
  create database test01;    //建立名为test的数据库
  show tables;        // 列出当前数据库下的表
  其他基本的增删改查使用标准SQL即可
  

  开放远程登录权限
  GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
  FLUSH PRIVILEGES;
  

  参考:
  老男孩
  http://blog.csdn.net/xxd851116/article/details/22947891
  http://www.xxlinux.com/article/development/database/20121106/18532.html
  

  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-452130-1-1.html 上篇帖子: 在CentOS 6.5 中安装KVM 虚拟机 下篇帖子: centos 下mv 命令的一次纠结
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表