安装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 资源比较丰富 |
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
#vi CMakeLists.txt #加上这些 才能生效 set(CMAKE_CXX_FLAGS "-g -O0 -Wall")
//防止出现gdb调试时,出现value has been optimized out,事实这些不起作用
-DWITH_DEBUG=1
|
4. 配置启动MySQL 5.5.14
1. 若有需要请先修改 mysql 的配置 my.cnf --defaults-file=/etc/my.cnf \ |