安装mysql5.6

 [MySQL] Linux下MySQL-5.6源码安装

    本文主要介绍centos下源码安装MySQL 5.6的方法,centos的版本为5.8.

    1)首先,你需要到MySQL官网下载源码tar包,点击MySQL Community Server,选择Source Code,源码包不大,只有34M左右。

    注:以下操作没有特殊说明,都是以root账户执行。

    2)先安装cmake(mysql5.5以后源码安装都得通过cmake编译)

    [plain]

    # yum install cmake

    并确保以下两个包已安装最新版:

    ncurses

    ncurses-devel

    3)添加MySQL用户组和用户

    [plain]

    # groupadd mysql

    # useradd mysql

    4)创建MySQL软件安装目录和数据存放目录

    [plain]

    mkdir -p /opt/mysql #MySQL安装目录

    chown -R mysql:mysql /opt/mysql

    mkdir -p /data/mysql #MySQL数据存放目录

    mkdir -p /data/mysql/data #存放数据

    mkdir -p /data/mysql/log #存放日志

    mkdir -p /data/mysql/tmp #存放临时文件

    chown -R mysql:mysql /data/mysql

    5)cmake编译安装MySQL

    [plain]

    tar zxvf mysql-5.6.13.tar.gz

    cd mysql-5.6.13

    cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/opt/mysql/etc  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1

    make

    make install

    参数说明:

    -DCMAKE_INSTALL_PREFIX=/opt/mysql    //指定安装目录

    -DINSTALL_DATADIR=/data/mysql      //指定数据存放目录

    -DSYSCONFDIR=/opt/mysql         //指定配置文件目录(本例的配置文件为/opt/mysql/my.cnf)

    -DDEFAULT_CHARSET=utf8         //指定字符集

    -DDEFAULT_COLLATION=utf8_general_ci   //指定校验字符

    -DEXTRA_CHARSETS=all          //安装所有扩展字符集

    -DENABLED_LOCAL_INFILE=1        //允许从本地导入数据

    上述步骤执行成功后,MySQL软件已成功安装至/opt/mysql目录下。

    7)编辑配置文件my.cnf  --不知道是哪个目录下的 

是安装目录下的配置文件,/opt/mysql/my.cnf 在进行第八步之后会在/opt/mysql出现此文件

    [plain]

    [client]

    socket = /opt/mysql/run/mysql.sock

    [innotop]

    socket = /opt/mysql/run/mysql.sock

    [mysql]

    prompt = \\u@\\d \\r:\\m:\\s>

    no-auto-rehash

    [mysqld_safe]

    pid-file = /opt/mysql/run/mysqld.pid

    [mysqld]

    #### Baes dir ####

    basedir = /opt/mysql

    datadir = /data/mysql/data

    tmpdir = /data/mysql/tmp

    socket = /opt/mysql/run/mysql.sock

    #### Base configure info ####

    port = 3306

    skip-name-resolve

    old_passwords = 0

    lower_case_table_names = 1

    open_files_limit = 65535

    read_rnd_buffer_size = 5M

    max_allowed_packet = 24M

    max_connect_errors = 50000

    max_connections = 1000

    max_user_connections = 950

    thread_cache_size=64

    table_open_cache=1024

    thread_stack=262144

    wait_timeout=864000

    #### Log info ####

    log-error = /data/mysql/log/alert.log

    slow_query_log=1

    slow_query_log_file= /data/mysql/log/slow.log

    log-slow-admin-statements

    long_query_time = 0.1

    slow_launch_time=1

    #### Binary log && Relay log ####

    binlog_format='MIXED'

    log-bin = /data/mysql/log/mysql-bin

    log-slave-updates = 1

    relay-log = /data/mysql/log/mysqld-relay-bin

    relay-log-index = /data/mysql/log/mysqld-relay-bin.index

    master-info-file = /data/mysql/log/master.info

    relay-log-info-file = /data/mysql/log/relay-log.info

    max_binlog_size = 500M

    max_binlog_cache_size = 2G

    #### query cache ####

    query_cache_size = 100M

    query_cache_limit = 1K

    query_cache_min_res_unit = 1K

    query_cache_type=2

    #myisam

    concurrent_insert = 2

    key_buffer_size = 100M

    sort_buffer_size = 100K

    join_buffer_size = 100K

    read_buffer_size = 1M

    myisam_sort_buffer_size = 100M

    #innodb plugin

    #innodb

    default-storage-engine = INNODB

    innodb_flush_method = O_DIRECT

    innodb_file_per_table = 1

    innodb_open_files=60000

    innodb_flush_log_at_trx_commit = 2

    innodb_lock_wait_timeout = 100

    innodb_additional_mem_pool_size = 20M

    innodb_buffer_pool_size = 16G

    innodb_log_buffer_size= 400M

    innodb_log_file_size = 100M

    innodb_log_files_in_group = 4

    innodb_file_io_threads = 4

    innodb_thread_concurrency = 16

    innodb_max_dirty_pages_pct = 50

    transaction-isolation = READ-COMMITTED

    innodb_data_file_path = ibdata1:10G;ibdata2:5G:autoextend

    innodb_buffer_pool_instances=4

    innodb_thread_concurrency=32

    ### Server id ####

    log_bin_trust_function_creators=1

    read_only=0

    server_id=5

    8)创建数据库

    [plain]

    cd /opt/mysql

    ./scripts/mysql_install_db --user=mysql

    上述建库语句将根据my.cnf里设置的数据文件目录和日志文件目录,生成相应的数据文件和日志文件,并创建系统数据库(如mysql,test,information_schema,performance_schema)

    9)设置root密码,创建只读账号

    [plain]

    export PATH=$PATH:/opt/mysql/bin   --?????????添加到任意地点执行的命令 直接就添加进来了

不执行此步会出现不识别mysql的错误信息

    mysqladmin -u root password '***'

    mysql -uroot -p

    root@(none) 06:08:34>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '***' WITH GRANT OPTION; --红线不要有空格

授权之后,始终没有连上的原因是没有关闭防火墙

    root@(none) 06:08:44>GRANT SELECT ON *.* TO 'rnd'@'%' IDENTIFIED BY '***';

    10)最后,把MySQL加入系统启动项和开机启动

    [plain]

    cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动

    chmod 755 /etc/init.d/mysqld #增加执行权限

    chkconfig mysqld on #加入开机启动

    这样,执行service mysqld start即可启动MySQL了:)。


安装总结:

知识要点:mkdir函数里面使用到了mkdir的-p选项。mkdir的-p选项允许你一次性创建多层次的目录,而不是一次只创建单独的目录

1:yum intall gcc-c++

yum install bison  

  yum  install perl- Data - Dumper
 yum install perl-ExtUtils、、
yum install perl*
2  service mysqld status /start/stop /restart

MySQL 5.5.20
-- Could NOT  find Threads  (missing:  Threads_FOUND)
CMake Error at configure.cmake:152 (LIST):
   list sub- command REMOVE_DUPLICATES requires list to be present.
Call Stack (most recent call first):
   CMakeLists.txt:246 (INCLUDE)
 
 
-- Could NOT  find Threads  (missing:  Threads_FOUND)
-- Check  if the system is big endian
-- Searching 16 bit integer
CMake Error at  /usr/share/cmake/Modules/TestBigEndian .cmake:31 (MESSAGE):
   no suitable  type found
Call Stack (most recent call first):
   configure.cmake:526 (TEST_BIG_ENDIAN)
   CMakeLists.txt:246 (INCLUDE)
 
 
-- Configuring incomplete, errors occurred!
删除掉mysql解压目录下的CMakeCache.txt文件



Google了下 ,问题可能的原因有多种,具体什么原因最好的办法是先查看下错误日志:
1、可能是/usr/local/mysql/data/mysql.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data”  然后重新启动mysqld!

2、可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9  进程号”杀死,然后重新启动mysqld!

3、可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !

4、mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data

5、skip-federated字段问题
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。

6、错误日志目录不存在
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限

7、selinux惹的祸,如果是centos系统,默认会开启selinux
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。

本次安装:my.cnf里tmpdir写成了tempdir写错了,

这是/data/mysql/data下的日志:localhost.localdomain.err
150515 10:12:36 mysqld_safe mysqld from pid file /opt/mysql/run/mysqld.pid ended
150515 10:15:39 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data
2015-05-15 10:15:39 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-15 10:15:39 4115 [Note] Plugin 'FEDERATED' is disabled.
/opt/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist
2015-05-15 10:15:39 4115 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2015-05-15 10:15:39 4115 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-05-15 10:15:39 4115 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-15 10:15:39 4115 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-15 10:15:39 4115 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-15 10:15:39 4115 [Note] InnoDB: Using CPU crc32 instructions
2015-05-15 10:15:39 4115 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-15 10:15:39 4115 [Note] InnoDB: Completed initialization of buffer pool
2015-05-15 10:15:39 4115 [Note] InnoDB: Highest supported file format is Barracuda.
2015-05-15 10:15:39 4115 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-15 10:15:39 4115 [Note] InnoDB: Waiting for purge to start
2015-05-15 10:15:39 4115 [Note] InnoDB: 5.6.16 started; log sequence number 1600847
2015-05-15 10:15:39 4115 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 47fc8531-faa8-11e4-aaaf-000c299b9396.
2015-05-15 10:15:39 4115 [Note] Server hostname (bind-address): '*'; port: 3306
2015-05-15 10:15:39 4115 [Note] IPv6 is available.
2015-05-15 10:15:39 4115 [Note]   - '::' resolves to '::';
2015-05-15 10:15:39 4115 [Note] Server socket created on IP: '::'.
2015-05-15 10:15:39 4115 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

本次安装在
    ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data这样问题才得以解决


vi my.cnf  在最下面增加[client]
socket=/opt/mysql/run/mysql.sock


一:结果安装成功了,但是使用root登录时遇到了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)错误. 如下所示

关掉mysql的服务

然后使用mysqld_safe命令在启动mysql,更新root账号的密码

--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。

--skip-networking :跳过TCP/IP协议,只在本机访问(从网上有些资料看,这个选项不是必须的。可以不用)

root@DB-Server init.d]# ./bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

mysql -u root mysql:
[root@DB-Server init.d]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2014, 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> select Host, User, Password,password_expired
    -> from user
    -> where user='root' and host='root' or host='localhost';
+-----------+------+-------------------------------------------+------------------+
| Host      | User | Password                                  | password_expired |
+-----------+------+-------------------------------------------+------------------+
| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y                |
+-----------+------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
 
mysql> update user set password=PASSWORD('p12#456')
    -> where user='root' and host='root' or host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit

mysql -u root -p

另外,如果登录mysql数据库后执行脚本遭遇 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,可以使用重新设置一次密码即可解决问题.

mysql>set password = password('p12#456'); 

 

至此问题解决,但是还有不少地方有些疑惑,为啥出现这个错误? 其实这么多资料都只是说了解决方法,但是都回避了问题的原因。

参考资料:

http://huangyifa163.blog.163.com/blog/static/262875752011127102215790/

http://sundful.iteye.com/blog/704337

http://wenku.baidu.com/view/735ffa41be1e650e52ea995a.html

http://www.cnblogs.com/sunson/articles/2172086.html

http://blog.163.com/eric1945@126/blog/static/164934572201081494343373/

http://www.cnblogs.com/likai198981/archive/2013/04/06/3002518.html



二:出现了本地不能连上mysql的问题,关上Linux的防火墙
















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值