作者:刘德华 | 来源:互联网 | 2023-08-20 15:21
1.首先安装依赖包shell>#yum-yinstallgccgcc-c++ncursesncurses-develcmake2.添加mysql用户shell>#userad
1.首先安装依赖包
shell>#yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
2.添加mysql用户
shell>#useradd -M -s /sbin/nologin mysql
3.创建mysql安装目录和数据存储目录
shell>#mkdir -p /usr/local/web/mysql
shell>#mkdir -p /usr/local/web/mysql/data
4.安装mysql5.6
http://dev.mysql.com/downloads/mysql/ 下载最新的 mysql源码包,使用下面命令下载编译和安装 mysql包:
shell># wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-i686.tar.gz
shell>#tar -zxvf mysql-5.6.35-linux-glibc2.5-i686.tar.gz
shell>#cd mysql-5.6.35-linux-glibc2.5-i686
/*使用cmake进行配置*/
shell>#cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/web/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/web/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/web/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
/*编译和安装*/
shell>#make && make install
/*复制配置文件*/
shell>#cp support-files/my-medium.cnf /etc/my.cnf
5.设置mysql运行时的所属组和用户
shell>#chown -R mysql.mysql /usr/local/web/mysql
shell>#chown -R mysql:mysql /usr/local/web/mysql
6.执行初始化配置脚本,创建系统自带的数据库和表
shell>#/usr/local/web/mysql/scripts/mysql_install_db \
--user=mysql \
--basedir=/usr/local/web/mysql \
--datadir=/usr/local/web/mysql/data &
7.复制服务启动脚本
shell>#cp /usr/local/web/mysql/support-files/mysql.server /etc/init.d/mysqld
8.启动mysql
shell>#service mysqld start
9.设置开机启动
方式1:
shell># vi /etc/rc.d/rc.local
在 文件中增加启动相关服务的命令如下:
/usr/local/mysql/bin/mysqld_safe --user=mysql &
方式2:
shell>#chkconfig --level 35 mysqld on
10.加入环境变量
shell>#vi /etc/profile
加入一下两句
PATH=$PATH:/usr/local/web/mysql/bin:/usr/local/web/mysql/lib/
export PATH
保存推出,让其立即生效
shell>#source /etc/profile
11. 修改root密码
shell>#mysqladmin -u root password 'new-password'
12.登录数据库
shell>#mysql -uroot -p
如下图所示,表示mysql安装成功