当前位置:首页 » 编程软件 » centos7编译安装mysql

centos7编译安装mysql

发布时间: 2024-07-26 14:41:01

Ⅰ centos7怎样安装mysql服务器

本人博客供参考

网页链接

下载mysql源安装包shell> wgethttp://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep “mysql.-community.”

shell> mysql -uroot -p
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass4!’;
或者:
mysql> set password for ‘root’@’localhost’=password(‘MyNewPass4!’);
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
mysql> GRANT ALL PRIVILEGES ON.TO ‘yangxin’@’%’ IDENTIFIED BY ‘Yangxin0917!’ WITH GRANT OPTION;

以上部分个人实践过,以下内容待实践

数据库存emoji 表情问题

mysql> SHOW VARIABLES WHERE Variable_name LIKE ‘character_set_%’ OR Variable_name LIKE ‘collation%’;
+————————–+——————-+
| Variable_name | Value |
+————————–+——————-+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+————————–+——————-+
10 rows in set (0.02 sec)
可以看到我的mysql版本是5.7的,utf8mb4有一个使用限制,mysql版本必须是5.5以上,大家需要注意,我目前用的ubuntu系统是16.04的。当前mysql的字符集配置如上表,我们的目的是更改成utf8mb4。
3.找到mysql的配置文件,可用命令
sudo find / -name my.cnf
我的配置文件位置如下,个别的位置有所不同
/etc/mysql/mysql.conf.d/mysqld.cnf

4.修改配置文件
在原文中添加以下内容:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=’SET NAMES utf8mb4’
原文件中无“[client]”和“[mysql]”,需要手动添加上。
……

Here is entries for some specific programs

The following values assume you have at least 32M ram

[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#

* Basic Settings

#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=’SET NAMES utf8mb4’
#

Instead of skip-networking the default is now to listen only on

……

5.重启mysql服务
sudo service mysql restart

6.查看结果
mysql> SHOW VARIABLES WHERE Variable_name LIKE ‘character_set_%’ OR Variable_name LIKE ‘collation%’;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 3
Current database:* NONE *
+————————–+——————–+
| Variable_name | Value |
+————————–+——————–+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+————————–+——————–+
10 rows in set (0.00 sec)

Ⅱ centos7镐庝箞瀹夎卪ysql

1銆丆entos 7 榛樿や笉鏀鎸乵ysql 锛堥兘鏄锲犱负阍憋级锛屾墍浠centos 7榛樿ゆ敮鎸佺殑鏄痬ariadb

浣曚负mariadb锛

MariaDB鏁版嵁搴撶$悊绯荤粺鏄疢ySQL镄勪竴涓鍒嗘敮锛屼富瑕佺敱寮婧愮ぞ鍖哄湪缁存姢锛岄噰鐢℅PL鎺堟潈璁稿彲 MariaDB镄勭洰镄勬槸瀹屽叏鍏煎筂ySQL锛屽寘𨰾珹PI鍜屽懡浠よ岋纴浣夸箣鑳借交𨱒炬垚涓篗ySQL镄勪唬镟垮搧銆傚湪瀛桦偍寮曟搸鏂归溃锛屼娇鐢╔traDB𨱒ヤ唬镟萦ySQL镄処nnoDB銆 MariaDB鐢尽ySQL镄勫垱濮嬩汉Michael Widenius涓诲煎紑鍙戯纴浠栨棭鍓嶆浘浠10浜跨编鍏幂殑浠锋牸锛屽皢镊宸卞垱寤虹殑鍏鍙窭ySQL AB鍗栫粰浜哠UN锛屾ゅ悗锛岄殢镌SUN琚鐢查ㄦ枃鏀惰喘锛孧ySQL镄勬墍链夋潈涔熻惤鍏Oracle镄勬坠涓銆侻ariaDB钖岖О𨱒ヨ嚜Michael Widenius镄勫コ鍎萦aria镄勫悕瀛椼

璇村埌杩欙纴鎴戜釜浜哄己鐑堟帹钻愬ぇ瀹跺紑濮嫔︿範MariaDB,褰撶劧鐢变簬鎴戜滑涓浜涢”鐩杩樻槸瑕佺敤mysql镄勶纴镓浠ヤ笉鑳芥斁寮冦傜湡涓嶉毦瀛︺

鎺ヤ笅𨱒 鎴戣蹭竴涓媍entos 7瀵筸ysql镄勫畨瑁呰繃绋

1銆佸傛灉涓瀹氲佸湪centos 7涓婂畨瑁卪ysql 锛岄渶瑕佸嵏杞组ariaDB锛屽惁鍒欎细鍐茬獊銆

2銆佹墽琛岃繖涓锻戒护锛歳pm -qa | grep mariadb

3銆佽繖镞朵细鍑虹幇涓浜涘垪琛锛岄兘鏄痬ariadb镄勫寘锛屾帴涓嬫潵鎴戜滑瑕佸共鎺

4銆佹墽琛屽备笅锻戒护rpm -e 钬搉odeps mariadb-libs-XXXXX.x86_64 锛堟敞镒忔垜杩欓噷镄刹xxx, 瑕佹牴鎹绗涓夋ュ嚭鐜扮殑鍒楄〃 锛屾尐涓骞)

5銆佸共瀹屽悗锛屽氨鍙浠ュ畨瑁卪ysql浜嗐

6銆佸幓搴﹀樻悳绱mysql镄剅pm鍖咃纴涓澶ф妸銆傛垜鐢ㄧ殑鏄5.6.22 .(镓句笉鍒扮殑锛岄梾鎴戣)

ww

杩欓噷闇瑕佸畨瑁 镊冲皯2涓锛1涓鏄痬ysql-server-xxxx.rpm 锛堣繖涓灏辨槸链嶅姟绔), 杩樻湁涓涓鏄痬ysql-client-xxxx.rpm(杩欎釜鏄瀹㈡埛绔锛屼笉𨱍宠咃纻涓嶈呯殑璇濅綘娌℃硶鍒濆嫔寲root瀵嗙爜锛屾眰镍)

7銆佹墽琛 rpm -ivh 钬滀笂闱涓や釜鏂囦欢钖 钬

8銆佽繖镙峰氨瑁呭ソ浜嗐

9銆佺劧钖 镓ц:service mysql start (濡傛灉OK锛岃存槑瑁呭ソ浜)

10銆佸啀铹跺悗镓ц岋细service mysql stop (涓嶈侀梾涓轰粈涔堬纴锲犱负榛樿root娌℃湁瀵嗙爜锛屼綘杩涗笉铡,镓浠ユ帴涓嬫潵鎴戜滑瑕佺粫杩囧瘑镰佺橱褰)

11銆佹墽琛岃繖涓锻戒护:mysqld_safe 钬摇ser=mysql 钬搒kip-grant-tables 钬搒kip-networking & mysql -u root mysql (涔熷氨鏄锛岃佸瓙涓岖敤瀵嗙爜鐩存帴锏诲綍锛岃繖镞秏ysql链嶅姟蹇呴’鍏抽棴鐘舵)

12銆佺劧钖庢墽琛岃繖涓锻戒护锛歎PDATE user SET Password=PASSWORD(钬榅XXXX钬) where USER=钬檙oot钬; 杩欓噷灏辨槸瀵箁oot璐﹀彿鍒濆嫔寲瀵嗙爜锛寈xx镊琛屾敼锛屼笉瑕佸缮浜嗐傚缮鎺夌殑璇濆氨瑕佺敤绗11姝ュ埯濮嫔寲锛堣皝璇存病链夊瘑镰佸氨涓嶈兘杩沵ysql?锛

13銆佺劧钖庢墽琛 flush privileges; 锛堟敞镒忎笉瑕佸缮璁版渶钖庣殑鍒嗗彿锛屽繀椤绘湁锛屼笉瑕侀梾涓轰粈涔)

14銆佺劧钖庤緭鍏quit; 阃鍑簃ysql瀹㈡埛绔銆

15銆侀吨鏂板惎锷╩ysql,锻戒护锛歴ervice mysql start

16銆佺劧钖庣敤root璐﹀彿锏诲綍 锻戒护:mysql -u root -p (鎺ヤ笅𨱒ヤ细鎻愮ず浣犺緭鍏ュ瘑镰侊纴姝ゆ椂灞忓箷涓嶅彲瑙侊纴涓嶈佷互涓烘绘満浜)

17銆佽繖镞堕殢渚挎墽琛屼竴涓狲ql,璀濡 show databases;

18銆佽繖镞朵细鎶ラ敊锛屽ぇ绾︽槸You must SET PASSWORD before executing this statement .鍏跺疄灏辨槸鎴戜滑甯歌佺殑锛氱涓娆$橱褰曢渶瑕佹敼瀵嗙爜,

19銆侀偅鎴戜滑灏辨敼涓鏀瑰惂锛屽弽姝d笉浼氭瀛

20銆佹墽琛 SET PASSWORD = PASSWORD(钬榵xxx钬); 娉ㄦ剰鍒嗗彿锛屼篃鍙浠ユ妸瀵嗙爜璺熶笂闱㈡闷寰椾竴镙枫

21銆佺劧钖庡啀铡绘墽琛 涓浜泂ql锛岀湅鐪嫔逛笉瀵广傚圭殑璇涨uit;

22銆佹渶钖庯纴鎴戜滑链濂藉惂mysql閲嶅惎涓涓. service mysql restart

23銆佺劧钖庨厤缃杩灭▼鍙浠ヨ繛鎺ワ纸娉ㄦ剰鍒氭墠鎴戜滑閮芥槸鍦ㄦ湰链烘搷浣灭殑鍝~~~~锛

24銆佷緷铹秏ysql -u root -p 杈揿叆瀵嗙爜钖庣橱鍏

25銆佹墽琛岋细GRANT ALL PRIVILEGES ON *.* TO 钬榬oot钬橜钬%钬 IDENTIFIED BY 钬樿繖閲屽~浣犵殑瀵嗙爜钬 WITH GRANT OPTION; (杩欓噷root@钖庨溃镄勭栌鍒嗗彿浠h〃鍏ㄥ畤瀹欓兘鍙浠ヨ繛鎺ヤ綘镄刴ysql,鍙瑕佺煡阆揿瘑镰) ,濡傛灉鏄浠呬粎鍏佽告煇涓狪P杩炴帴锛岄偅涔堟妸杩欎釜锏惧垎鍙锋崲鎴愭煇涓猧p鍗冲彲

26 銆丗LUSH PRIVILEGES; 骞朵笖阃鍑

27銆佷缭闄╄捣瑙侊纴鍐嶉吨钖痬ysql链嶅姟

濂藉惂锛孙K浜嗐傛帴涓嬫潵澶у跺彲浠ョ敤navicate 铡昏繛鎺ュ暒

Ⅲ 如何在linux系统中centos7.6上面安装mysql数据库

安装mysql基本有三种办法:

1,源码编译。 2,二进制包方式安装 3, yum安装。

可以采用二进制包方式安装mysql,并进行优化配置。

1.安装之前,先创建mysql用户

[root@linuxprobe_nfs ~]# useradd mysql -s /sbin/nologin -M

[root@linuxprobe_nfs ~]# id mysql

uid=500(mysql) gid=500(mysql) groups=500(mysql)

2.软件包的下载及解压

[root@linuxprobe_nfs ~]# mkdir /home/chenfan/tools -p

[root@linuxprobe_nfs ~]# cd /home/chenfan/tools

在http://dev.mysql.com/downloads/mysql/官网上下载mysql-5.5.32-linux2.6-x86_64.tar.gz

[root@linuxprobe_nfs tools]# ls

mysql-5.5.32-linux2.6-x86_64.tar.gz

[root@linuxprobe_nfs tools]# tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz

[root@linuxprobe_nfs tools]# ls

mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32-linux2.6-x86_64.tar.gz

[root@linuxprobe_nfs local]# mv mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql-5.5.32
###免编译安装 mysql二进制包安装与配置实战记录

[root@linuxprobe_nfs local]# cd /usr/local

[root@linuxprobe_nfs local]# ln -s mysql-5.5.32 mysql

###此处的软链接为了版本升级提供了便利

3.初始化数据库

[root@linuxprobe_nfs local]# mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

###此处如果初始化发生错误,删除data目录下的内容,rm -fr mysql/data/*,重新初始化。

4.生成MySQL配置文件

[root@linuxprobe_nfs local]# cd mysql

[root@linuxprobe_nfs mysql]# cp support-files/my-small.cnf /etc/my.cnf

5.授权管理文件

[root@linuxprobe_nfs ~]# chown -R mysql:mysql /usr/local/mysql/

[root@linuxprobe_nfs ~]# ls -ld /usr/local/mysql/

drwxr-xr-x. 13 mysql mysql 4096 Jun 24 17:21 /usr/local/mysql/

6.设置科学的启动方式

[root@linuxprobe_nfs mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@linuxprobe_nfs mysql]# chmod +x /etc/init.d/mysqld

[root@linuxprobe_nfs mysql]# /etc/init.d/mysqld start

Starting MySQL... SUCCESS!

[root@linuxprobe_nfs mysql]# chkconfig --add mysqld

[root@linuxprobe_nfs mysql]# chkconfig mysqld on

[root@linuxprobe_nfs mysql]# chkconfig --list mysqld

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

### 设置开机自启动mysql

7.配置MySQL环境变量

[root@linuxprobe_nfs mysql]# echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile

[root@linuxprobe_nfs mysql]# source /etc/profile

[root@linuxprobe_nfs mysql]# echo $PATH

/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

###此处PATH路径的设置为了后续mysql命令的使用

8.mysql登陆与密码设置

[root@linuxprobe_nfs mysql]# mysql

Ⅳ centos7 怎么安装mysql

CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。
1. 下载mysql的repo源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安装mysql-community-release-el7-5.noarch.rpm包
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
3. 安装mysql
$ sudo yum install mysql-server

根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。
4. 重置密码
重置密码前,首先要登录
$ mysql -u root

登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
$ sudo chown -R openscanner:openscanner /var/lib/mysql

然后,重启服务:
$ service mysqld restart

接下来登录重置密码:
$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > exit;

5. 开放3306端口
$ sudo vim /etc/sysconfig/iptables

添加以下内容:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

保存后重启防火墙:
$ sudo service iptables restart

这样从其它客户机也可以连接上mysql服务了。

热点内容
a算法概念 发布:2024-11-25 21:24:16 浏览:587
jquery源码书籍 发布:2024-11-25 21:19:50 浏览:803
银行卡输入密码超限怎么办 发布:2024-11-25 21:09:07 浏览:958
编译指令多发 发布:2024-11-25 20:58:17 浏览:751
java上传文件到服务器 发布:2024-11-25 20:52:47 浏览:741
轴加工编程 发布:2024-11-25 20:52:12 浏览:412
手机的媒体存储 发布:2024-11-25 20:29:42 浏览:265
安卓如何关闭手机桌面 发布:2024-11-25 20:24:37 浏览:701
脚本也违法吗 发布:2024-11-25 20:24:24 浏览:305
phpeol 发布:2024-11-25 20:16:01 浏览:93