Linux下安装mysql-5.7.30(笔记)
1.检查库文件是否存在,如果存在则删除
[root@host-172-16-5-7 ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[root@host-172-16-5-7 ~]# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps
/sbin/ldconfig: File /usr/lib64/libpq.so.5.8 is empty, not checked.
[root@host-172-16-5-7 ~]# rpm -qa | grep mysql
整个安装过程参考如下文档进行:
http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
2.Mysql依赖于libaio库
yum search libaio # search for info
yum install libaio # install library
rpm -q libaio
rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
3.分别执行以下步骤安装Mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar -zxvf /root/soft/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local
mv mysql-5.7.30-linux-glibc2.12-x86_64 mysql
cd mysql
chown -R mysql:mysql ./
cd bin
./mysqld --initialize --user=mysql(会得到一串默认密码)
./mysqld_safe --user=mysql &
4.安装后的配置
上传my.cnf文件值/etc下(mysql5.7.17之后的版本就没有my.cnf了,需要自己新建,配置文件从其他地方拷贝即可)
添加mysql环境变量
vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
source /etc/profile
下面这一步可选
cp support-files/mysql.server /etc/init.d/mysqld
5.启动mysql
service mysqld start
或者
cd support-files
./mysql.server start
至此,mysql就安装好并启动成功了。
6.修改root密码:
采用
cd mysql/bin
mysql -uroot -p
登录的时候,输入前面记录的root密码,提示密码不正确,没办法,我们只好自己去修改root密码了
进入到sql后以后在通过如下命令修改一次密码,否则无法进行其他操作:
mysql> SET PASSWORD = PASSWORD('123456');
mysql远程连接报错: Host * is not allowed to connect to this MySQL server
mysql -u root -p password
mysql>use mysql;
mysql>update user set host ='%' where user ='root' and host ='localhost';
mysql>flush privileges;