mysql版本:Server version: 5.6.17 Source distribution,编译安装路径/usr/local/msyql

系统环境:

# uname -a

Linux swallow 2.6.32-431.el6.x86_64 #1 SMPFri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

  • 首先初始化mysql(生成数据库的结构)

# ./scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

这里需要注意如果以前的数据库在运行,必须关掉。不然。是不停的循环。CRTctrl+c ctrl+z都停不下来。

再接下来出现2OK就说明成功了。

这个是系统自带的my.cnf /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommendedto prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

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

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

 

  • 启动服务

[root@swallow mysql]#./support-files/mysql.server start

Starting MySQL... ERROR! Theserver quit without updating PID file (/usr/local/mysql/data/swallow.pid).

修改my.cnf

[mysqld]

basedir = /usr/local/mysql

 datadir = /usr/local/mysql/data

 port= 3306

 server_id = 1

 socket = /usr/local/mysql/data/mysql.sock

 user= mysql

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]

log-error=/usr/local/mysql/data/mysqld.log

pid-file=/usr/local/mysql/data/swallow.pid

然后将 my.cnf 替换系统自带的

# \mv my.cnf  /etc/my.cnf

# ./support-files/mysql.server start

Starting MySQL. SUCCESS!

服务启动成功。

basedir = /usr/local/mysql

 datadir = /usr/local/mysql/data

2个参数也可以在启动脚本(./support-files/mysql.serve)里面修改。

  • 连接msyql

# ./bin/mysql

ERROR 2002 (HY000): Can't connectto local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

出现错误。

修改配置文件:

       vim/etc/my.cnf

在末尾添加:

[client]

default-character-set=utf8

socket=/usr/local/mysql/data/mysql.sock

这里需要注意的是:不要在中间插入:因为 my.cnf 格式的模块是松散的没有明确的结束标志。容易把别的字段的配置隔断。造成无法解析。

# ./bin/mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.17 Source distribution

 

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql>

今天重新安装mysql做mysql主从。发现原来哪些配置都是安装的时候加入的。如果需要修改只能通过修改配置文件my.cnf在启动的时候重新读取配置文件my.cnf 特别是在做多个 mysql实例的时候。就需要这些配置的支持。安装mysql的一些编译参数
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    #指定安装路径
    -DMYSQL_DATADIR=/usr/local/mysql/data \
    #指定mysql数据(库)文件的存放路径
    -DSYSCONFDIR=/etc \
    #配置文件
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    #引擎支持myisam
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    #引擎支持 innodb
    -DWITH_MEMORY_STORAGE_ENGINE=1 \
    #引擎支持 memory-storage
    -DWITH_READLINE=1 \

    -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
    #指定mysql的sock文件路径
    -DMYSQL_TCP_PORT=3306 \
    #指定mysql端口号

成功连接数据库。开始新的学习篇章。