首页

文章

centos怎么安装mysql

发布网友 发布时间:2022-02-26 19:21

我来回答

2个回答

懂视网 时间:2022-02-26 23:42

产品型号:Thinkpad E15

系统版本:centos7

软件版本:mysql 5.7

mysql安装教程

1.使用yum安装mysql数据库的软件包 

[root@xuegod63 ~]# yum -y install mariadb-server mariadb 

注:  

mariadb-server  #MariaDB数据库 

mariadb      # MariaDB服务器Linux下客户端 

注:从centos7系统开始,系统中自带的mysql数据库变成了mariadb-server,mariadb-server和mysql操作上一样。mariadb-server是mysql的一个分支。

2.启动数据库服务

[root@xuegod63 ~]# systemctl start  mariadb #启动MariaDB服务

[root@xuegod63 ~]# systemctl enable  mariadb #设置开启自动启动MariaDB服务

3. 安装完mariadb-server后,运行mysql_secure_installation去除安全隐患

[root@xuegod63 ~]# mysql_secure_installation #进入安全配置导向

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

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):  #初次运行直接回车,因为root用户没有密码

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] Y #是否设置root用户密码,输入Y

New password: 123456  #新密码123456

Re-enter new password: 123456

Password updated successfully!

。。。

Remove anonymous users? [Y/n] Y  #是否删除匿名用户,生产环境建议删除,所以直接回车或Y

 ... Success!

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] Y #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止

 ... Success!

By default, MariaDB 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.

Remove test database and access to it? [Y/n] Y  #是否删除test数据库,直接回车或Y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] Y  #是否重新加载权限表,直接回车

 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

… Success!

至此数据库安装成功。

4. 登录数据库

[root@xuegod63 ~]# mysql -u root -p123456 

MariaDB [(none)]> show databases;    #没有test数据库 #执行时,所有命令以;号结尾 

+-------------------------+ 

| Database

+-------------------------+ 

| information_schema

| mysql

| ucenter

+-------------------------+ 

3 rows in set (0.00 sec) 

MariaDB [(none)]> exit #退出命令可以加分号,也可以不加分号。

总结:

1、使用yum安装mysql数据库的软件包 

2、启动数据库服务

3、运行mysql_secure_installation去除安全隐患

4、登录数据库

热心网友 时间:2022-02-26 20:50

当前位置: > CentOS服务器 > 数据库服务器 > MySQL >
centos6.5下安装mysql
时间:2014-08-12 01:11来源:blog.csdn.net 作者:brushli 举报 点击:17509次
1.使用yum命令安装mysql
[html] view plaincopy
[root@bogon ~]# yum -y install mysql-server
2.设置开机启动
[html] view plaincopy
[root@bogon ~]# chkconfig mysqld on
3.启动MySQL服务
[html] view plaincopy
[root@bogon ~]# service mysqld start
4.设置MySQL的root用户设置密码
[html] view plaincopy
[root@bogon ~]# mysql -u root
mysql> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
+------+-----------+----------+
5 rows in set (0.01 sec)
查询用户的密码,都为空,用下面的命令设置root的密码为root
[html] view plaincopy
mysql> set password for root@localhost=password('root');
mysql> exit
5.用新密码登陆
[html] view plaincopy
[root@bogon ~]# mysql -u root -p
Enter password:
6.创建mysql新用户test_user
[html] view plaincopy
mysql> create user 'test_user'@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
7.给新用户test_user授权,让他可以从外部登陆和本地登陆
注意:@左边是用户名,右边是域名、IP和%,表示可以访问mysql的域名和IP,%表示外部任何地址都能访问。
[html] view plaincopy
mysql> grant all privileges on *.* to 'test_user'@'localhost' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'test_user'@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+----------+-----------+-------------------------------------------+
| user | host | password |
+----------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | bogon | |
| root | 127.0.0.1 | |
| | localhost | |
| | bogon | |
| test_user | % | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
| test_user | localhost | *3046CF87132BBD4FDDF06F321C6859074843B7D3 |
+----------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
8.查看mysql5.1的默认存储引擎
从下面的执行结果可以看出,mysql的默认引擎是MyISAM,这个引擎是不支持事务的。
[html] view plaincopy
mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)
也可以以下面的方式查看
[html] view plaincopy
mysql> show variables like 'storage_engine';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | MyISAM |
+----------------+--------+
1 row in set (0.00 sec)
9.修改mysql的默认引擎为InnoDB
9.1 停止mysql
[html] view plaincopy
mysql> exit;
[root@bogon ~]# service mysqld stop
9.2 修改/etc/my.cnf
[mysqld] 后加入
[html] view plaincopy
default-storage-engine=InnoDB
加入后my.cnf的内容为:
[html] view plaincopy
[root@bogon etc]# more my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

default-storage-engine=InnoDB

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
9.3 启动mysql
[html] view plaincopy
[root@bogon etc]# service mysqld start
Starting mysqld: [ OK ]
9.4 查看mysql默认存储引擎
[html] view plaincopy
[root@bogon etc]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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 variables like 'storage_engine';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.00 sec)
10.CentOS6.5开放mysql端口3306
CentOS6.5默认是不开放端口的,如果要让外部的系统访问CentOS6.5上的mysql,必须开放mysql的端口3306
10.1 修改/etc/sysconfig/iptables
添加下面一行
[html] view plaincopy
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
修改后iptables中的内容是
[html] view plaincopy
[root@bogon etc]# more /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#添加配置项
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT
11.重启防火墙
[html] view plaincopy
[root@bogon etc]# service iptables restart
这样就可以从外部访问mysql了。
至此,mysql在CentOS6.5上的安装过程、用户创建、外部访问的步骤全部完成。
长春小飞没有车没有房 碳钢的多久生锈 碳钢多久会生锈 碳钢多长时间会开始生锈 碳钢和铝哪个容易生锈 梦见天宫图是什么意思 光遇2023好友树解锁图鉴 光遇二级节点多少个 ...火柴小女孩》《词语手册》里有很多词语的意思的,求告知 暖融融解释 领淘通淘客助手这个软件怎么样? 淘宝客必备的九大工具有哪些? 电脑里硬盘如何共享怎么实现多台电脑共用一块硬盘 两台电脑一个硬盘两台电脑是否可以同时用一个硬盘 共享电脑硬盘怎样设置局域网电脑硬盘共享 现在下载歌曲好还是不下好 故障码P033D的含义解析 切菜机多功能型切菜机 scanbox三维扫描仪 苹果13没有删除的备忘录怎么恢复? iphone备忘录永久删除怎么恢复?iphone备忘录恢复最近删除文件方法介绍... 备忘录最近删除怎么找 初一班主任工作计划 新初一班主任工作计划 359度是什么角 报个 定向乡镇卫生院 的医学好不好 酒驾缓刑节保证书怎么写 合同法律咨询免费 这款充电宝可以带上飞机吗? 倪俊卿成就及荣誉 江苏种牛站有几家? 山东宏正牧业有限公司服务承诺 吃早餐后抽血会影响体检结果吗 电脑如何设置护眼模式(台式电脑如何设置护眼模式) 电脑显示器设置护眼电脑屏幕怎么设置比较护眼 广告机是否支持分屏显示功能? 上海东丰船务有限公司怎么样? 马弗炉管厂家 CF手游体验服怎样获取资格 穿越火线体验服在哪申请资格_cf手游体验服资格申请入口链接 穿越火线体验服资格申请链接在哪-穿越火线体验服资格申请链接介绍 快手浏览量多少才能赚钱?快手靠浏览量能挣多少钱? 小麦胚芽如何吃最好 个头怎么造句 高跟鞋走路磨脚该如何处理? 除螨虫的特效药 螨虫什么药物可以除掉 网上在哪买奢侈品 二手包包闲置了怎么办 夫妻想要怀孕要提前做哪些准备 手机图片如何投屏到电视上去 手机图片投屏到电视上去的方法 分区助手无法压缩卷怎么处理? 微信怎么15人语音聊天 centos怎么安装mysql数据库 centos怎样安装mysqld centos 怎么安装mysql 微信怎么知道对方有没删除自己 centos7.2的mysql怎么安装 如何知道对方是不是删除自己微信 怎么微信知道对方有没有删除自己 微信怎么知道对方有没有删除自己 MySQL密码忘了怎么办 mysql root原始密码忘记了怎么办 更改mysql密码忘记了 root密码怎么办 微信怎样才知道对方有没有删除自己的好友 电脑可以远程控制电脑吗 iphone手机把联系人设置黑名单,打电话来的人会提示什么 word中如何利用文本框和表格进行复杂版面编排 如何要word中制作复杂的表格,(上下线不对齐且行列合并多) 这样的复杂性三线表怎么用word制作,要详细步凑,万分感谢! word里的复杂表格制作 linux系统下怎么安装mysql 微信不能语音聊天了怎么办? “centos”怎样安装“mysql”客户端? 微信怎么才能语音聊天 如何在centos中安装mysql 微信如何用语音聊天 centos下怎么装MYSQL 如何在centos安装mysql 为什么微信语音聊天功能无法使用? centos 7怎么安装mysql 如何在centos7中安装mysql 电脑上微信怎么语音聊天 求助,centos6.2系统怎么安装mysql啊,请大神指点! 网页版微信如何语音聊天 linux下的mysql客户端怎么安装 如何判断centos中是否安装了mysql? 怎么在centos上装mysql 怎么把mysql安装到linux 微信不能语音说话了,是怎么回事? 如何安装mysql linux 微信电脑版怎么语音聊天
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com