centos7安装mysql7
.安装之前的准备
卸载centos7自带的mariadb
rpm -qa|grep mariadb #查看一下是否有mariadb相关的包
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64 #把查询到的包卸载
1.
2.
下载mysql安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.60.tar.gz
1.
下载cmake安装包
wget https://cmake.org/files/v3.10/cmake-3.10.2.tar.gz
1.
添加mysql用户和组
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql # -s /sbin/nologin 表示禁止该用户登录,加强安全; -g mysql 指定属于mysql组; -M 表示不创建用户家目录
1.
2.
安装ncurses-devel
yum install ncurses-devel -y
1.
安装cmake
tar zxvf cmake-3.10.2.tar.gz -C /usr/local
cd /usr/local/cmake-3.10.2
./configure
gmake && gmake install
1.
2.
3.
4.
2.安装myqsl
tar zxvf mysql-5.5.60.tar.gz
cd mysql-5.5.60
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.60 -DMYSQL_DATADIR=/application/mysql-5.5.60/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.60/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
make && make install
1.
2.
3.
4.
做软连接
ln -s /application/mysql-5.5.60/ /application/mysql
1.
mysql目录授权
chown -R mysql:mysql /application/mysql-5.5.60/
1.
复制相关文件
cd /application/mysql/support-files
cp my-small.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
1.
2.
3.
4.
mysql初始化
cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
1.
2.
启动mysql
/etc/init.d/mysqld start
1.
配置环境变量
echo 'export PATH=/application/mysql/bin:$PATH'>>/etc/profile
source /etc/profile
1.
2.
配置登陆密码
/application/mysql//bin/mysqladmin -u root password 'zacs164.com'
1.
设置mysql开机启动
chkconfig mysqld on
chkconfig --list mysqld #查看一下
1.
2.
登录mysql
正常的情况是可以正常登陆进去的,但是我在登录的时候报了以下错误信息:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
1.
解决方法:
1.停止mysql数据库
/etc/init.d/mysqld stop
1.
2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
1.
3.使用root登录mysql数据库
mysql -u root mysql
1.
4.更新root密码
UPDATE user SET Password=PASSWORD('ZACS164.COM') where USER='root';
1.
5.刷新权限
FLUSH PRIVILEGES;
1.
6.退出mysql
7.重启mysql
/etc/init.d/mysqld restart
1.