【Mysql】Linux编译安装
原创
©著作权归作者所有:来自51CTO博客作者原来是咔咔的原创作品,请联系作者获取转载授权,否则将追究法律责任
author:咔咔
这里就是会遇到设置密码问题,这个问题,我在下面文章已经写了,可以看,如果是不需要修改密码的,就不用管了
从CentOS 7.0发布以来,yum源中开始使用mariadb来代替MySQL的安装。即使你输入的是yum install mysql , 显示的也是mariadb的安装内容。
首先先卸载mariadb。
检查mariadb是否已安装
1 2
|
[root@localhost ~]# yum list installed | grep mariadb mariadb-libs.x86_64 1:5.5.56-2.el7 @anaconda
|
全部卸载
卸载默认安装的mariadb
安装Mysql
一、下载安装官方提供的yum rpm包
下载网页:https://dev.mysql.com/downloads/repo/yum/
点击Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package后面的download,进入新的页面点击No thanks, just start my download.就可以看到下载源地址了。
下载wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
1
|
wget https: //repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
|
安装rpm包
1
|
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
|
检查mysql的yum源是否安装成功:yum repolist enabled | grep "mysql.*-community.*"
1 2 3 4
|
[root@localhost src]# yum repolist enabled | grep "mysql.*-community.*" mysql-connectors-community/x86_64 MySQL Connectors Community 51 mysql-tools-community/x86_64 MySQL Tools Community 63 mysql80-community/x86_64 MySQL 8.0 Community Server 17
|
二、使用yum install mysql-server安装(这里会有点慢)
1
|
yum -y install mysql-server
|
查看版本信息
三、启动mysql
1 2
|
[root@localhost ~]# service mysqld start Redirecting to /bin/systemctl start mysqld.service
|
四、使用初始密码登录
1 2
|
[root@localhost ~]# cat / var /log/mysqld.log|grep 'A temporary password' 2018-05-18T02:01:17.558742Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: belPU>iuF4*H
|
最后一行冒号后面的部分belPU>iuF4*H就是初始密码。
五、mysql5.7开始对root密码复杂性要求很高,必须有数字、字母大小写、符号(应该是需要8位以上),这里我么还查show databases;不了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.11 Copyright (c) 2000, 2018, 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> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
|
只需要把root密码更改的复杂一些即可。
更改密码方法:
1 2 3 4 5 6 7 8 9
|
解决办法 1、 修改用户密码 mysql> alter user 'root' @ 'localhost' identified by 'youpassword' ; 或者(下面这个只能修改当前登录的用户密码) mysql> set password=password( "youpassword" ); 2、刷新权限 mysql> flush privileges;
|
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
mysql> alter user 'root' @ 'localhost' identified by 'qA123,./' ; Query OK, 0 rows affected (0.10 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)
|
重启mysqld服务。
1
|
[root@localhost ~]# systemctl restart mysqld.service
|
1 2 3 4 5 6 7 8
|
常用的命令: systemctl start mysqld #启动mysqld systemctl stop mysqld #停止mysqld systemctl restart mysqld #重启mysqld systemctl enable mysqld #设置开机启动 systemctl status mysqld #查看 MySQL Server 状态
|