web项目完整的基础入门级搭建(二):MySql+Jenkins

MySql安装

1. 查看该操作系统上是否已经安装了mysql数据库

rpm -qa | grep mysql

2. 移除CentOS默认的mysql-libs

yum remove mysql-libs

3. 清空dbcache

yum clean dbcache

4. 下载MySQL rpm安装包

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

5. 安装下载的rpm文件

这个rpm还不是mysql的安装文件,只是两个yum源文件,执行后,在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo

rpm -ivh mysql-community-release-el6-5.noarch.rpm

6. 查看是否已经有mysql可安装文件

yum repolist all | grep mysql

7. 安装mysql-community-server(选项都用yes)

yum install mysql-community-server

8. 启动

service mysqld start

==> Starting mysqld:                                           [  OK  ]

9. mysql的root用户的密码

默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码。这个root账号是mysql的root账号,非Linux的root账号

mysql -u root
use mysql;

//这里的分号,一定要加上。因为是sql语句。不然就失败
update user set password=PASSWORD("这里输入root用户密码") where User='root';

flush privileges; 

10. 查看mysql是否自启动,并且设置开启自启动命令

chkconfig --list | grep mysqld
chkconfig mysqld on

11. mysql安全设置

可以不执行这一步操作。直接开始使用数据库。如果执行了这一步的操作。那么远程连接数据库会失败。需要再做处理。处理方式见后面的 踩坑说明

mysql_secure_installation
  • 没设置过密码,就直接回车
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
  • 设置一个密码
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
  • yes,来移除匿名用户
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
  • no,允许root远程连接库
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] n
  • yes,删除测试库
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
  • yes,最后一步让刚才的设置生效,重启配置
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y

12. 查看mysql 默认端口号

//登录
mysql mysql -u root -p //输入密码

//查看端口号
show global variables like 'port'

//查看端口占用的程序 (查看所有netstat -anp)
netstat -anp|grep 3306

13. 常用命令

//进入库
mysql -u root -p;
use mysql;

//重启
service mysqld restart

//启动
service mysqld start

//配置
/etc/my.cnf 

//连接
mysql -h IP -u root -p 密码;

踩坑说明

  • 无法远程连接mysql。

有四种可能,下面文章中有说明。

https://blog.csdn.net/qivan/article/details/79752574

下面说明其中两种情况。

  • mysql没有开启远程连接问题

经过上面第11步的配置,即【11. mysql安全设置】。也是需要做如下处理。(执行语句记得加分号“;”结尾)

mysql -uroot -p

Enter password: 

mysql> use mysql

//下面root为用户名,mypasswd为密码 all为全部权限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypasswd' WITH GRANT OPTION;  

//flush privileges;让我们刚才的操作立即生效
mysql> flush privileges;  
  • 安全组策略无法远程连接问题

具体的设置。需要登陆你的云服务控制台,在安全组里面添加响应的端口即可。

avatar

avatar

[站外图片上传中...(image-39fd43-1556439372590)]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。