安装mysql

转自 http://www.iteye.com/topic/1128407

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/log/error.log --pid-file=/usr/local/mysql/data/mysql.pid --socket=/usr/local/mysql/mysql.sock

 主从同步

grant all privileges on *.* to replication@'%' identified by "123456" with grant option;
flush privileges;

change  master to master_host='xxx',master_user='xxx',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=902;

 show grants for test@'%';

MySQL自5.5版本以后,就开始使用cmake 编译工具了。

 

CentOS安装MySQL时报Curses library not found解决

yum install ncurses-devel

rm CMakeCache.txt

 

0)安装linux centos 6.5

1)安装g++

  yum list gcc-c++

  yum install gcc-c++.x86_64

2)安装各种软件

  yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison

 

3)安装mysql

  wget  http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.41.tar.gz

  tar  zxvf mysql-5.6.41.tar.gz && cd mysql-5.6.41

  vi CMakeLists.txt

    #加上这些 才能生效, 如果要GDB调度的话

    set(CMAKE_CXX_FLAGS "-g -O0 -Wall")
    set(CMAKE_C_FLAGS "-gdwarf-2 -g3 -g -O0 -Wall")

    set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0 -Wall")
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0 -Wall")

    如果安装报错

    /software/mysql-5.6.35/strings/ctype-ucs2.c:49:22: error: ?.factor?.defined but not used [-Werror=unused-variable]
 static unsigned long lfactor[9]=

    删除49,50行

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=1

 

  make && make install

  如果还不行,删除包,再解压,重新执行

4)配置mysql

  groupadd mysql && useradd -g mysql mysql

  chmod -R 777 /usr/local/mysql/data

  chown -R mysql.mysql /usr/local/mysql

  mkdir -p /usr/local/mysql/log && cd /usr/local/mysql/log && touch error.log &&  chmod 777 error.log

  cp /home/source/mysql-5.6.41/support-files/mysql.server /etc/init.d/mysqld

  chmod +x /etc/init.d/mysqld 

  vi /etc/init.d/mysqld

  basedir=/usr/local/mysql
  datadir=/usr/local/mysql/data

  f)  vi /etc/my.cnf  

从库

relay-log=relay-log

relay-log-index=relay-log.index

server-id=2

 

主库

server-id =1

log-bin = mysql-bin

 

[mysqld]
#datadir=/var/lib/mysql
socket=/usr/local/mysql/mysql.sock
user=mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/log/error.log
pid-file = /usr/local/mysql/data/mysql.pid
default-storage-engine=Innodb
user = mysql
secure_file_priv = /home/source
server-id =1
log-bin = mysql-bin
# Disabling symbolic
-links is recommended to prevent assorted security risks symbolic-links=0 explicit_defaults_for_timestamp=true [mysqld_safe] log-error = /usr/local/mysql/log/error.log pid-file = /usr/local/mysql/data/mysql.pid #log-error=/var/mysqld.log #pid-file=/var/run/mysqld/mysqld.pid

 

 

 

 

5)安装(这里的mysql配置文件使用默认的/etc/my.cnf)其配置内容跟 安装时制定的内容不一样,记得要改,不然要出错

 

/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql

 

6)服务器启动

       /usr/local/mysql/bin/mysqld_safe &

  /etc/init.d/mysqld start

 7)mysql客户端启动

  a) 基于unix sock

    /usr/local/mysql/bin/mysql  -uroot    -P3306 -p -S /usr/local/mysql/mysql.sock 

    等同于

    /usr/local/mysql/bin/mysql  -uroot    -P3306 -p

    

/usr/local/mysql/bin/mysql  -uroot    -hxxxx  -P3306 -p123456

 /usr/local/mysql/bin/mysql -uroot -S /var/lib/mysql/mysql.sock

(上面不用输入密码)

 

mysql服务器端启动

  /etc/init.d/mysqld start

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

使用mysql_safe启动

  /usr/local/mysql/bin/mysqld_safe  --user=mysql --basedir=/usr/loca/mysql  --datadir=/usr/loca/mysql/data &

  [1] 19352

  [root@localhost support-files]# 170703 07:25:07 mysqld_safe Logging to '/var/log/mysqld.log'.

  170703 07:25:07 mysqld_safe Starting mysqld daemon with databases from /usr/loca/mysql/data  

  170703 07:25:07 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

原因:

  my.cnf配置在安装时,默认安装在/etc/my.cnf和/usr/local/mysql/my.cnf里,默认使用第一个,当然可以指定

解决:

  /usr/local/mysql/bin/mysqld_safe  --user=mysql --basedir=/usr/loca/mysql  --datadir=/usr/loca/mysql/data  --defaults-file=/usr/local/mysql/my.cnf &

 报错了

 关于配置文件:

 

  /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/default-tpl.jx.diditaxi.com.pid --socket=/var/lib/mysql/mysql.sock &

  

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.49.tar.gz

tar zxvf mysql-5.5.49.tar.gz && cd mysql-5.5.49

#vi CMakeLists.txt

#加上这些 才能生效

set(CMAKE_CXX_FLAGS "-g -O0 -Wall")
set(CMAKE_C_FLAGS "-gdwarf-2 -g3 -g -O0 -Wall")

set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0 -Wall")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0 -Wall")

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306\

-DWITH_DEBUG=1

make && make install

useradd -g mysql mysql

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
cd support-files/

cp mysql.server /etc/init.d/mysqld

1. 若有需要请先修改 mysql 的配置 my.cnf

 

mkdir log

cd log

touch error.log

 


[root@localhost ~]# vi /etc/my.cnf
在[mysqld]下面添加
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/log/error.log
pid-file = /usr/local/mysql/data/mysql.pid
default-storage-engine=Innodb
user = mysql

2. mysql 初始化安装 执行以下命令

 

 

 

 

 

chmod -R 777 /usr/local/mysql/data

chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql

3. 将 mysql 加入开机启动
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --level 345 mysqld on

4. 为MySQL配置环境变量,以后使用起来方便
# vi /etc/profile
# export PATH=/usr/local/mysql/bin:$PATH

5. 启动 mysql
[root@localhost ~]# service mysqld start

 

5. 启动 mysql
[root@localhost ~]# service mysqld start

root密码进不去

/usr/local/mysql/bin/mysqld --skip-grant &

use mysql
//update user set password=password("123456") where user="root";


insert into mysql.user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv) values('%', 'root', PASSWORD('123456'),'Y','Y','Y','Y');

update user set Create_priv='Y', Drop_priv='Y', Reload_priv='Y',Shutdown_priv='Y', Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y', Repl_client_priv='Y', Alter_routine_priv='Y' where USER='root';


flush privileges;

//GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";

/etc/init.d/mysqld start

 

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --open-files-limit=65535 --pid-file=/var/lib/mysql/default-tpl.jx.diditaxi.com.pid --socket=/var/lib/mysql/mysql.sock

 

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/default-tpl.jx.diditaxi.com.pid --socket=/var/lib/mysql/mysql.sock

 

/usr/local/mysql/bin/mysql -uroot -S /var/lib/mysql/mysql.sock -p

yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*

 

 

这两个网站mysql 资源比较丰富 

mirrors.sohu.com
ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/
ftp://ftp.pku.edu.cn/open/db/MySQL/

1 安装所需要系统库相关库文件

[root@localhost ~]# yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*

 

这两个网站mysql 资源比较丰富 
ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/
ftp://ftp.pku.edu.cn/open/db/MySQL/


2. 安装 cmake  

[root@localhost ~]# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz 
[root@localhost ~]# yum install cmake

 
 3. 编译安装 MySQL 5.5.14 

[root@localhost ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.14.tar.gz

 

[root@localhost ~]# /usr/sbin/groupadd mysql 
[root@localhost ~]# /usr/sbin/useradd -g mysql mysql 

[root@localhost ~]# tar xvf mysql-5.5.14.tar.gz 
[root@localhost ~]# cd mysql-5.5.14/ 

 

#vi CMakeLists.txt

#加上这些 才能生效

set(CMAKE_CXX_FLAGS "-g -O0 -Wall")
set(CMAKE_C_FLAGS "-g -O0 -Wall")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0 -Wall")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0 -Wall")

 

//防止出现gdb调试时,出现value has been optimized out,事实这些不起作用
CFLAGS="-g -O0" CXX=gcc CXXFLAGS="-g -O0 -felide-constructors -fno-exceptions -fno-rtti"

 


[root@localhost ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql \

-DWITH_DEBUG=1

 


以上参数等说明: 
DCMAKE_INSTALL_PREFIX=/usr/local/mysql # mysql安装的主目录,默认为/usr/local/mysql 
DMYSQL_DATADIR=/usr/local/mysql/data # mysql数据库文件的存放目录,可以自定义 
DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock # 系统Socket文件(.sock)设置,基于该文件路径进行Socket链接,必须为绝对路径 
DSYSCONFDIR=/etc # mysql配置文件 my.cnf的存放地址,默认为/etc下 
DMYSQL_TCP_PORT=3306 # 数据库服务器监听端口,默认为3306 
DENABLED_LOCAL_INFILE=1 # 允许从本地导入数据 
DWITH_READLINE=1 # 快捷键功能 
DWITH_SSL=yes # 支持 SSL 
DMYSQL_USER=mysql # 默认为mysql 

//下面3个是数据库编码设置 
DEXTRA_CHARSETS=all # 安装所有扩展字符集,默认为all 
DDEFAULT_CHARSET=utf8 # 使用 utf8 字符 
DDEFAULT_COLLATION=utf8_general_ci # 校验字符 

//下面5个是数据库存储引擎设在 
DWITH_MYISAM_STORAGE_ENGINE=1 # 安装 myisam 存储引擎 
DWITH_INNOBASE_STORAGE_ENGINE=1 # 安装 innodb 存储引擎 
DWITH_ARCHIVE_STORAGE_ENGINE=1 # 安装 archive 存储引擎 
DWITH_BLACKHOLE_STORAGE_ENGINE=1 # 安装 blackhole 存储引擎 
DWITH_PARTITION_STORAGE_ENGINE=1 # 安装数据库分区 

执行安装,需要等很长时间
 

[root@localhost ~]#  make 
[root@localhost ~]#  make install 
 
[root@localhost ~]# chmod +w /usr/local/mysql 
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql   #改变目录拥有者与所属组 

[root@localhost ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16 
[root@localhost ~]# cd support-files/ 
[root@localhost ~]# cp my-large.cnf /etc/my.cnf # 选择默认 配置文件 适合大型服务器 
[root@localhost ~]# cp mysql.server /etc/init.d/mysqld    # 复制启动文件


4. 配置启动MySQL 5.5.14 

 

1. 若有需要请先修改 mysql 的配置 my.cnf 
[root@localhost ~]# vi /etc/my.cnf 
在[mysqld]下面添加 
basedir = /usr/local/mysql-5.5.14
datadir = /usr/local/mysql-5.5.14/data
log-error = /usr/local/mysql-5.5.14/mysql_error.log
pid-file = /usr/local/mysql-5.5.14/data/mysql.pid
default-storage-engine=MyISAM
user = mysql
 
2. mysql 初始化安装  执行以下命令 

[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db \

--defaults-file=/etc/my.cnf  \
--basedir=/usr/local/mysql \
--datadir=/var/lib/mysql\
--user=mysql 


3. 将 mysql 加入开机启动 
[root@localhost ~]# chmod +x /etc/init.d/mysqld 
[root@localhost ~]# vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:) 
basedir=/usr/local/mysql
datadir=/var/mysql/data

[root@localhost ~]# chkconfig --add mysqld 
[root@localhost ~]# chkconfig --level 345 mysqld on 

为MySQL配置环境变量,以后使用起来方便 
# export PATH=/usr/local/mysql/bin:$PATH

4. 启动 mysql 
[root@localhost ~]# service mysqld start 
设置密码 
[root@localhost ~]# mysql_secure_installation 

注意:如果出现 Starting MySQL...The server quit without updating PID file

 报错:

Starting MySQL...The server quit without updating PID file

 
查看错误日志

情景1: 
 
110206 12:58:35 [ERROR] Can't start server : Bind on unix socket: No such file or directory

110206 12:58:35 [ERROR] Do you already have another mysqld server running on socket: /mysql/mysqldir/data/mysql.sock ?

110206 12:58:35 [ERROR] Aborting
[root@localhost ~]# ps -ef | grep mysql # 未发现有mysqld. 
[root@localhost ~]# netstat -an | grep 3306 也未发现异常. 
最后从mysql安装目录下重新复制一个配置文件到/etc/my.cnf
修改相应参数.于是问题解决 


情景2: 
 /mysql/mysqldir/bin/mysqld: Table 'mysql.plugin' doesn't exist
 [ERROR] Can't open the mysql.plugin table. Please run my        sql_upgrade to create it.
原因:编译安装后忘记初始化表.
解决:运行mysql_install_db


 其他情况,查看日志文件(我的是localhost.localdomain.err,具体因人而异),然后具体分析;

 

posted @ 2015-05-26 16:03  taek  阅读(460)  评论(0编辑  收藏  举报