1、到mysql官网下载源码 http://dev.mysql.com/downloads/mysql/ 到Select Platform:下选择Source Code从下面选择Generic Linux 然后下载后传送到Linux
2、安装必须的依赖包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio libaio-devel perl-Data-Dumper net-tools
3、解压并编译
tar xvf mysql-5.7.17.tar.gzcd mysql-5.7.17cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 \-DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boostmake make install
4、创建mysql用户并给mysql用户赋予mysql程序安装目录的权限
useradd mysql -s /sbin/nologin chown -R mysql:mysql /usr/local/mysql mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/data
5、为mysql创建自带的数据库和表
cd /usr/local/mysql bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
6、注册为服务
cp support-files/mysql.server /etc/init.d/mysql
7、创建etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf
8、将mysql加入环境变量
[[email protected] rhel5~]# vi /root/.bash_profile 在PATH=$PATH:$HOME/bin添加参数为: PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib [[email protected] rhel5~]#source /root/.bash_profile
9、设置默认密码
mysql 5.7在安装后会默认生成一个随机密码存放在/root/.mysql_secret 查看改密码使用 cat /root/.mysql_secret 随后修改密码 mysqladmin -u root -p‘旧密码‘ password ‘新密码‘
10、启动mysql
systemctl start mysql
11、设置mysql远程访问
mysql -u root -proot GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘你的密码‘ WITH GRANT OPTION; FLUSH PRIVILEGES;
12、设置防火墙添加端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
13、设置myqsl开机启动
chkconfig –-add mysql chkconfig mysql on
时间: 2024-11-08 10:43:53