zoukankan      html  css  js  c++  java
  • centeros6.8 下安装mysql教程

    1.1 安装Mysql

    1.1.1 检查

    检查是否已安装mysql的相关包

    [root@localhost ~]# rpm -qa|grep -i mysql  

    一般情况下,centeros系统中会存在mysql-lib的文件,需要卸载

    卸载mysql-lib命令如下: 
          #rpm -e --nodeps  mysql-libs-5.1.61-4.el6.x86_64

    MySQL-server-5.6.19-1.el6.x86_64

    MySQL-client-5.6.19-1.el6.x86_64

    MySQL-devel-5.6.19-1.el6.x86_64

    若已安装移除rpm

    [root@localhost ~]# rpm -e  MySQL-server-5.6.19-1.el6.x86_64

    [root@localhost ~]# rpm -e  MySQL-client-5.6.19-1.el6.x86_64

    [root@localhost ~]# rpm -e  MySQL-devel-5.6.19-1.el6.x86_64

    删除/var/lib/mysql/

    [root@localhost ~]#rm -fr /var/lib/mysql/

    [root@localhost ~]#rm -fr /etc/my.cnf

    1.1.2 安装

    上传安装包

    [root@localhost ~]# cd soft/

    上传完成之后检查上传的mysql rpm包的权限:ls -al

    如果没有写的权限,则需要修改rpm包的权限:chmod -R 777  MySQL-client-5.6.19-1.el6.x86_64.rpm MySQL-devel-5.6.19-1.el6.x86_64.rpm MySQL-server-5.6.19-1.el6.x86_64.rpm  

    [root@localhost soft]# ll

    drwxr-xr-x  2 root root     4096 Sep  9 20:44 jdk

    -rwxr-xr-x. 1 root root 18360416 Jul  9 16:15 MySQL-client-5.6.19-1.el6.x86_64.rpm

    -rwxr-xr-x. 1 root root  3368712 Jul  9 16:14 MySQL-devel-5.6.19-1.el6.x86_64.rpm

    -rwxr-xr-x. 1 root root 54592892 Jul  9 16:13 MySQL-server-5.6.19-1.el6.x86_64.rpm

    安装

    [root@localhost soft]# rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm

    [root@localhost soft]# rpm -ivh MySQL-devel-5.6.19-1.el6.x86_64.rpm

    [root@localhost soft]# rpm -ivh MySQL-client-5.6.19-1.el6.x86_64.rpm

    修改配置文件位置

    [root@localhost soft]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf

    初始化MySQL

    [root@localhost soft]# /usr/bin/mysql_install_db

    启动服务

    [root@localhost soft]# service mysql start

    查看root账号密码

    [root@localhost soft]# cat /root/.mysql_secret

    # The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl

    注:命令的输出'qKTaFZnl'即为密码

    登陆数据库

    [root@localhost ~]# mysql -uroot –pqKTaFZnl

    重置root密码为123456

    mysql> SET PASSWORD = PASSWORD('1234abcd');

    退出数据库

    mysql> exit

    验证密码

    [root@localhost ~]# mysql -uroot -p1234abcd

    允许远程登陆

    安装后的配置

    1)登陆mysql数据库

    mysql> use mysql;

    2)查询主机,用户名,密码

    mysql> select host,user,password from user;

    +-----------------------+------+-------------------------------------------+

    | host                  | user | password                                  |

    +-----------------------+------+-------------------------------------------+

    | localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

    | localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |

    | 127.0.0.1             | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |

    | ::1                   | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |

    +-----------------------+------+-------------------------------------------+

    3)更新用户表,重置root密码

    mysql> update user set password=password('1234abcd') where user='root';

    4)允许远程登陆

    mysql> update user set host='%' where user='root' and host='localhost';

    5)刷新权限

    mysql> flush privileges;

    6)退出server

    mysql> exit

    设置开机自启动

    [root@localhost ~]# chkconfig mysql on

    1)查看启动级别--以下为正常

    [root@localhost ~]# chkconfig --list | grep mysql

    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

    MySQL的默认安装位置--查看目录或文件是否存在

    ----------------------------------------------------------------------

    1/var/lib/mysql/               #数据库目录

    2/usr/share/mysql              #配置文件目录

    修改字符集和数据存储路径

    配置/etc/my.cnf和/usr/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.

    vim /etc/my.cnf

    配置/etc/my.cnfvi /etc/my.cnf

    [mysqld]

    #log-slow-queries=/var/log/mysqllog/myslow.log

    #long_query_time=1

    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

    lower_case_table_name=1

    character-set-server=utf8

    collation-server=utf8_general_ci

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    [mysqld_safe]

    log-error=/var/log/mysqld.log

    pid-file=/var/run/mysqld/mysqld.pid

    log-slow-queries=/var/log/mysqllog/myslow.log

    long_query_time=1

    配置/usr/my.cnfvi /usr/my.cnf

    [mysqld]

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    ##max connections

    max_connection=1000

    重启mysql服务

    service mysql restart

    1.2 CentOS系统中防火墙默认是阻止3306端口的,我们要是想访问mysql数据库,我们需要这个端口,命令如下:

     /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

    我们需要保存我们的操作,命令如下:

      /etc/rc.d/init.d/iptables save

    此时我们可以查看端口的状态,命令如下:

     /etc/init.d/iptables status

    当然如果你打开其他端口也一样,只需要把这个端口号换乘你需要的端口号即可。

    到此mysql安装成功!!

     

  • 相关阅读:
    Android Sqlite 增删改查
    Android SQLiteOpenHelper Sqlite数据库升级onUpgrade
    Android SQLiteOpenHelper Sqlite数据库的创建与打开
    Android Xml,PullParser,解析
    Android Xml文件生成,Xml数据格式写入
    Android Studio生成get,set,tostring,构造方法
    Android SharedPreference
    Android 文件模式
    Android 权限的由来
    C++ essentials 之 union
  • 原文地址:https://www.cnblogs.com/zhangshitong/p/6867170.html
Copyright © 2011-2022 走看看