mysql 5 种安装方式:
yum
rpm
常规编译
二进制包,不用编译
cmake
mysql 5.5版本以上 机器数量少建议cmake 数量多二进制包
安装步骤:
1.安装一些常用的软件包:
yum -y install openldap-servers libevent-devel libevent uuid-devel
yum -y install bison bison-devel
yum -y install gcc gdb strace gcc-c++ autoconf
yum -y install libxml2 libxml2-devel zlib zlib-devel
yum -y install gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel cmake
yum -y install git
ncurses-devel (这个必须要装,mysql依赖它)
2.mysql 官网下载页面
MySQL Community Server 5.5.55
Looking for the latest GA version?
Select Version:
5.5.55
Select Operating System:
Source code (要选这个才是源代码包)(Linux-Generic 里面选择的.tar.gz 是二进制包)
Select OS Version:
3.安装cmake
wget https://github.com/Kitware/CMake/archive/master.zip
unzip master.zip
cd CMake-master/
./bootstrap 或者 ./configure
gmake
gmake install
3.安装数据库:
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.55-linux2.6-x86_64.tar.gz(这个是二进制包)
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.55.tar.gz
(这个才是源代码包,下载这个)
tar xf mysql-5.5.55.tar.gz
echo $?
cd mysql-5.5.55
添加mysql 用户
useradd mysql -s /sbin/nologin -M
编译
cmake \
-DCMAKE_INSTALL_PREFIX=/install/mysql \
-DMYSQL_DATADIR=/install/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.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
make && make install
配置环境变量:
echo ‘export PATH=/install/mysql/bin:$PATH‘ >> /etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
chown -R mysql.mysql /install/mysql/data/
chmod -R 1777 /tmp/
初始化:
cd /install/mysql/scripts/
./mysql_install_db --basedir=/install/mysql/ --datadir=/install/mysql/data/ --user=mysql
如果安装成功,会提示如下大串信息
成功的信息: Installing MySQL system tables... 170407 8:33:03 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 170407 8:33:03 [Note] /install/mysql//bin/mysqld (mysqld 5.5.55) starting as process 3037 ... OK Filling help tables... 170407 8:33:04 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 170407 8:33:04 [Note] /install/mysql//bin/mysqld (mysqld 5.5.55) starting as process 3044 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /install/mysql//bin/mysqladmin -u root password ‘new-password‘ /install/mysql//bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘ Alternatively you can run: /install/mysql//bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /install/mysql/ ; /install/mysql//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /install/mysql//mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ /bin/cp support-files/mysql.server /etc/init.d/mysqld
开机启动
/bin/cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
chkconfig --list
mkdir -p /var/lib/mysql
chown -R mysql.mysql /var/lib/mysql/
chmod -R 1777 /var/lib/mysql/
拷贝对应的mysql配置文件
cp /soft/src/mysql-5.5.55/support-files/my-huge.cnf /etc/my.cnf
启动:/etc/init.d/mysqld start
登录:
mysql
select user,host from mysql.user;
删除多余用户
delete from mysql.user where user=‘‘;
delete from mysql.user where host=‘localhost.localdomain‘;
delete from mysql.user where host=‘::1‘;
设置密码:
/install/mysql/bin/mysqladmin -u root password ‘new-password‘