一、编译安装mysql-5.5.32及其依赖包
1、安装依赖包
yum -y install ncurses-devel cmake
二、安装mysql
2.1、创建用户和组
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
2.2、下载mysql
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.32.tar.gz
三、解压编译mysql
tar xf mysql-5.5.32.tar.gz
cd mysql-5.5.32
3.1、编译mysql
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 -DMYSQL_DATADIR=/application/mysql-5.5.32/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_genneral_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,asscii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_EBGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
3.2、安装
make && make install
四、创建软连接
ln -s /application/mysql-5.5.32 /application/mysql
五、复制配置文件
cp /root/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
六、配置环境变量
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
七、初始化数据库
mkdir -p /application/mysql/data
chown -R mysql:mysql /application/mysql/
chmod -R 1777 /tmp
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
八、复制启动文件
cp /root/mysql-5.5.32/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
九、登录测试
[root@mysql mysql-5.5.32]# mysql
mysql: Collation 'utf8_genneral_ci' is not a compiled collation and is not specified in the '/application/mysql-5.5.32/share/charsets/Index.xml' file
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | mysql |
| root | mysql |
+------+-----------+
6 rows in set (0.00 sec)
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | mysql |
+------+-----------+
4 rows in set (0.00 sec)
十、设置新密码
/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h mysql password 'new-password'
附加内容:授权新用户
grant all privileges on *.* to system@'localhost' identified by '123com' with grant option;