码迷,mamicode.com
首页 > 数据库 > 详细

centos 7 安装mySql

时间:2015-09-13 15:51:44      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

1,准备mySql源码安装

  # wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.19.tar.gz

2:对于centos 7 安装mySql依赖项

      # yum install gcc-c++ make cmake bison bison-devel ncurses-devel libaio-devel perl

      # yum install perl-Data-Dumper

3:安装cmake,下载cmake-2.8.10.2.tar.gz,自行下载

      # tar -zxv -f cmake-2.8.10.2.tar.gz

      # cd cmake-2.8.10.2

      # ./configure

      # make

      # make install

       接下来配置cmake环境变量

      # vi /etc/profile 》》在该文件中末尾追加下面两行

        PATH=/usr/local/cmake-2.8.10.2/bin:$PATH
        export PATH

      # source /etc/profile  》》执行后修改生效

      # echo $PATH    》》查看PATH值

4:安装mySql

      创建安装路径和数据库保存路径

      安装路径: mkdir -p /usr/lcoal/mysql

      数据库路径:mkdir -p /usr/local/mysql/data

      创建mysql用户和组

                     groupadd mysql

                     useradd -r -g mysql mysql

      编译安装mysql

        # tar -zxv -f mysql-5.6.19.tar.gz

        # cd mysql-5.6.19

        #

     cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
     -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
     -DDEFAULT_CHARSET=utf8 \
     -DDEFAULT_COLLATION=utf8_general_ci \
     -DWITH_MYISAM_STORAGE_ENGINE=1 \
     -DWITH_INNOBASE_STORAGE_ENGINE=1 \
     -DWITH_MEMORY_STORAGE_ENGINE=1 \
     -DWITH_READLINE=1 \
     -DENABLED_LOCAL_INFILE=1 \
     -DMYSQL_DATADIR=/mnt/db/mysql/data \
     -DMYSQL_USER=root \
     -DMYSQL_TCP_PORT=5001      

        # make 

        # make install

 

        检查是否安装成功

        到安装目录下 ls

        bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
有bin等以上文件的话,恭喜你已经成功安装了mysql。

 

        将mysql的启动服务添加到系统服务中

        # cp support-files/my-medium.cnf /etc/my.cnf

          cp:是否覆盖"/etc/my.cnf"? y

 

       创建系统数据库的表

       # cd /usr/local/mysql

       # scripts/mysql_install_db --user=mysql

 

        设置环境变量

        # vi /root/.bash_profile

        在修改PATH=$PATH:$HOME/bin为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

        # source /root/.bash_profile //使刚才的修改生效

 

手动启动mysql

[root@localhost ~]# cd /usr/local/mysql  [root@localhost mysql]# ./bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止 mysqladmin -u root -p shutdown //此时root还没密码,所以为空值,提示输入密码时,直接回车即可。

将mysql的启动服务添加到系统服务中

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

启动mysql

[root@localhost mysql]# service mysql start  Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

启动失败:  我这里是权限问题,先改变权限 [root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql

接着启动服务器 [root@localhost mysql]# /etc/init.d/mysql start

修改MySQL的root用户的密码以及打开远程连接

[root@localhost mysql]# mysql -u root mysql

mysql> use mysql;  mysql> desc user;  mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力 mysql> update user set Password = password(‘123456‘) where User=‘root‘; //设置root用户密码 mysql> select Host,User,Password from user where User=‘root‘;  mysql> flush privileges;  mysql> exit

重新登录

[root@localhost mysql]# mysql -u root -p  Enter password:123456

若还不能进行远程连接,关闭防火墙 [root@localhost]# /etc/rc.d/init.d/iptables stop

centos 7 安装mySql

标签:

原文地址:http://www.cnblogs.com/Yongzhouunknown/p/4805038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!