准备:
下载MySQL源码文件包:https://edelivery.oracle.com/ 去网站注册登录找到需要的源码包进行下载。
yum remove *mysql* find / -name mysql --删除旧文件目录
创建用户:
groupadd mysql1 --创建mysql1的组 useradd -g mysql1 mysql1 --创建mysql1的用户 passwd mysql1
安装依赖包:
cp -r mysql-5.6.25 /home/mysql1 chown -R mysql1:mysql1 /home/mysql1 yum install make gcc-c++ cmake bison ncurses ncurses-devel
安装:
su - mysql1 cd /home/mysql1/mysql-5.6.25 cmake -DCMAKE_INSTALL_PREFIX=/home/mysql1/mysql \ --安装目录 -DMYSQL_DATADIR=/home/mysql1/mysql/data \ --目录文件 -DSYSCONFDIR=/home/mysql1/mysql\ --配置文件 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/home/mysql1/mysql/mysql.sock \ --sock文件路径 -DMYSQL_TCP_PORT=3306 \ --端口 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 \ --字符编码 -DDEFAULT_COLLATION=utf8_general_ci --回车等待cmake完成
make && make install
配置环境变量:
vi .bash_profile export MYSQL_HOME=/home/mysql1/mysql export PATH=$MYSQL_HOME/bin:$PATH
编辑/home/mysql1/mysql/my.cnf参数文件:
[mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /home/mysql1/mysql datadir = /home/mysql1/mysql/data port = 3306 server_id = 1 socket = /home/mysql1/mysql/mysql.sock pid-file = /home/mysql1/mysql/mysql.pid #long_query_time = 1 #log-slow-queries = /home/mysql1/mysql/mysql-slow.log # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
保存退出;
注册服务:
cp /home/mysql1/mysql/support/mysql.server /etc/rc.d/init.d/mysql1 chkconfig --add mysql1 service mysql1 start
初始化数据库:
scripts/mysql_install_db --basedir=/home/mysql1/mysql --datadir=/home/mysql1/mysql/data --user=mysql1 --user为系统登录用户
更改root初始密码:
mysqladmin -uroot password ‘mysql1‘
登录:
mysql -uroot -p --进行登录
[同台服务器安装第二个mysql]
groupadd mysql2 useradd -g mysql2 mysql2 cp -r mysql-5.6.25 /home/mysql2 cmake -DCMAKE_INSTALL_PREFIX=/home/mysql2/mysql -DMYSQL_DATADIR=/home/mysql2/mysql/data -DSYSCONFDIR=/home/mysql2/mysql-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/home/mysql2/mysql/mysql.sock -DMYSQL_TCP_PORT=3307 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make && make install
vi .bash_profile export MYSQL_HOME=/home/mysql2/mysql export PATH=$MYSQL_HOME/bin:$PATH
编辑/home/mysql1/mysql/my.cnf
[mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /home/mysql2/mysql datadir = /home/mysql2/mysql/data port = 3307 server_id = 2 socket = /home/mysql2/mysql/mysql.sock pid-file = /home/mysql2/mysql/mysql.pid #long_query_time = 1 # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
保存退出;
cp /home/mysql2/mysql/support/mysql.server /etc/rc.d/init.d/mysql2 chkconfig --add mysql2 service mysql2 start /home/mysql2/mysql/scripts/mysql_install_db --basedir=/home/mysql2/mysql --datadir=/home/mysql2/mysql/data --user=mysql2 --user为系统登录用户 mysqladmin -uroot password ‘mysql2‘ mysql -uroot -p --进行登录
时间: 2024-11-07 22:26:25