關於linux上安裝mysql筆記的信息

本文目錄一覽:

怎麼在linux上安裝mysql

1. 運行平台:CentOS 6.3 x86_64,基本等同於RHEL 6.3

2. 安裝方法:

安裝MySQL主要有兩種方法:一種是通過源碼自行編譯安裝,這種適合高級用戶定製MySQL的特性,這裡不做說明;另一種是通過編譯過的二進制文件進行安裝。二進制文件安裝的方法又分為兩種:一種是不針對特定平台的通用安裝方法,使用的二進制文件是後綴為.tar.gz的壓縮文件;第二種是使用RPM或其他包進行安裝,這種安裝進程會自動完成系統的相關配置,所以比較方便。

3. 下載安裝包:

a. 官方下載地址:

或鏡像文件下載:

2. 下載文件(根據操作系統選擇相應的發布版本):

a. 通用安裝方法

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

b. RPM安裝方法:

MySQL-server-5.5.29-2.el6.x86_64.rpm

MySQL-client-5.5.29-2.el6.x86_64.rpm

4. 通用安裝步驟

a. 檢查是否已安裝,grep的-i選項表示匹配時忽略大小寫

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

*可見已經安裝了庫文件,應該先卸載,不然會出現覆蓋錯誤。注意卸:載時使用了–nodeps選項,忽略了依賴關係:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 –nodeps

b. 添加mysql組和mysql用戶,用於設置mysql安裝目錄文件所有者和所屬組。

[root@localhost JavaEE]#groupadd mysql

[root@localhost JavaEE]#useradd -r -g mysql mysql

*useradd -r參數表示mysql用戶是系統用戶,不可用於登錄系統。

c. 將二進制文件解壓到指定的安裝目錄,我們這裡指定為/usr/local

[root@localhost ~]# cd/usr/local/

[root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz

*加壓後在/usr/local/生成了解壓後的文件夾mysql-5.5.29-linux2.6-x86_64,這名字太長,我們為它建立一個符號鏈接mysql,方便輸入。

[root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql

d. /usr/local/mysql/下的目錄結構

Directory

Contents of Directory

bin

Client programs and the mysqld server

data

Log files, databases

docs

Manual in Info format

man

Unix manual pages

include

Include (header) files

lib

Libraries

scripts

mysql_install_db

share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

sql-bench

Benchmarks

e. 進入mysql文件夾,也就是mysql所在的目錄,並更改所屬的組和用戶。

[root@localhost local]#cd mysql

[root@localhost mysql]#chown -R mysql .

[root@localhost mysql]#chgrp -R mysql .

f. 執行mysql_install_db腳本,對mysql中的data目錄進行初始化並創建一些系統表格。注意mysql服務進程mysqld運行時會訪問data目錄,所以必須由啟動mysqld進程的用戶(就是我們之前設置的mysql用戶)執行這個腳本,或者用root執行,但是加上參數–user=mysql。

[root@localhost mysql]scripts/mysql_install_db –user=mysql

*如果mysql的安裝目錄(解壓目錄)不是/usr/local/mysql,那麼還必須指定目錄參數,如

[root@localhost mysql]scripts/mysql_install_db –user=mysql \

–basedir=/opt/mysql/mysql \

–datadir=/opt/mysql/mysql/data

*將mysql/目錄下除了data/目錄的所有文件,改回root用戶所有,mysql用戶只需作為mysql/data/目錄下所有文件的所有者。

[root@localhost mysql]chown -R root .

[root@localhost mysql]chown -R mysql data

g. 複製配置文件

[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf

h. 將mysqld服務加入開機自啟動項。

*首先需要將scripts/mysql.server服務腳本複製到/etc/init.d/,並重命名為mysqld。

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

*通過chkconfig命令將mysqld服務加入到自啟動服務項中。

[root@localhost mysql]#chkconfig –add mysqld

*注意服務名稱mysqld就是我們將mysql.server複製到/etc/init.d/時重命名的名稱。

*查看是否添加成功

[root@localhost mysql]#chkconfig –list mysqld

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

i. 重啟系統,mysqld就會自動啟動了。

*檢查是否啟動

[root@localhost mysql]#netstat -anp|grep mysqld

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld

unix 2 [ ACC ] STREAM LISTENING 14396 2365/mysqld /tmp/mysql.sock

*如果不想重新啟動,那可以直接手動啟動。

[root@localhost mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j. 運行客戶端程序mysql,在mysql/bin目錄中,測試能否連接到mysqld。

[root@localhost mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor. Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

Type ‘help;’ or ‘\h’ forhelp. Type ‘\c’ to clear the current input statement.

mysql quit

Bye

*此時會出現mysql命令提示符,可以輸入sql語句,輸入quit或exit退出。為了避免每次都輸入mysql的全路徑/usr/local/mysql/bin/mysql,可將其加入環境變量中,在/etc/profile最後加入兩行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

這樣就可以在shell中直接輸入mysql命令來啟動客戶端程序了

[root@localhost mysql]#mysql

Welcome to the MySQLmonitor. Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

Type ‘help;’ or ‘\h’ forhelp. Type ‘\c’ to clear the current input statement.

mysql

5. RPM安裝步驟

a. 檢查是否已安裝,grep的-i選項表示匹配時忽略大小寫

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

可見已經安裝了庫文件,應該先卸載,不然會出現覆蓋錯誤。注意卸載時使用了–nodeps選項,忽略了依賴關係:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 –nodeps

2. 安裝MySQL的服務器端軟件,注意切換到root用戶:

[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm

安裝完成後,安裝進程會在Linux中添加一個mysql組,以及屬於mysql組的用戶mysql。可通過id命令查看:

[root@localhost JavaEE]#id mysql

uid=496(mysql)gid=493(mysql) groups=493(mysql)

MySQL服務器安裝之後雖然配置了相關文件,但並沒有自動啟動mysqld服務,需自行啟動:

[root@localhost JavaEE]#service mysql start

Starting MySQL.. SUCCESS!

可通過檢查端口是否開啟來查看MySQL是否正常啟動:

[root@localhost JavaEE]#netstat -anp|grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld

c. 安裝MySQL的客戶端軟件:

[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm

如果安裝成功應該可以運行mysql命令,注意必須是mysqld服務以及開啟:

[root@localhost JavaEE]#mysql

Welcome to the MySQLmonitor. Commands end with ; or \g.

Your MySQL connection idis 1

Server version: 5.5.29MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners.

Type ‘help;’ or ‘\h’ forhelp. Type ‘\c’ to clear the current input statement.

mysql

d. RPM安裝方式文件分布

Directory

Contents of Directory

/usr/bin

Client programs and scripts

/usr/sbin

The mysqld server

/var/lib/mysql

Log files, databases

/usr/share/info

Manual in Info format

/usr/share/man

Unix manual pages

/usr/include/mysql

Include (header) files

/usr/lib/mysql

Libraries

/usr/share/mysql

Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation

/usr/share/sql-bench

Benchmarks

linux服務器上怎麼安裝mysql

安裝包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz

使用xshell連接linux服務器,使用root用戶名登錄,依次執行以下命令:

======================================================

/usr/sbin/groupadd mysql 【添加mysql組】

/usr/sbin/useradd -d /var/lib/mysql -s /sbin/nologin -g mysql mysql

mkdir -p /usr/local/src/mysql 【新建mysql文件夾】

cd / 【打開上傳安裝包的目錄】

mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 【上傳安裝包到服務器的根目錄下】

mv mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz /usr/local/src/mysql【根目錄的安裝包移動到文件夾下】

cd /usr/local/src/mysql【打開目錄】

tar -zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz【解壓安裝包】

cp mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql -r【複製文件】

cd /usr/local【打開目錄】

chown -R mysql:mysql mysql/

cd /usr/local/mysql/scripts/【打開目錄】

./mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data【執行腳本】

cd /usr/local/mysql/support-files【打開目錄】

cp my-default.cnf /etc/my.cnf【複製文件到新的路徑下及文件名】

cp: overwrite `/etc/my.cnf’?Y【Y】

cp mysql.server /etc/init.d/mysql【複製文件到新的路徑下】

vim /etc/profile【編輯軟件運行環境】

vim i(編輯一些內容) esc(進入normal) w(保存文件) q(不保存退出文件)

###############################################################

export MYSQL_HOME=/usr/local/mysql

export PATH=$MYSQL_HOME/bin:$PATH

###############################################################

source /etc/profile

chkconfig –add mysql

chkconfig mysql on

service mysql start

/usr/local/mysql/bin/mysqladmin -u root password ‘rootroot’【修改數據庫root的密碼】

grant all privileges on tdcdb.* to ‘root’@’%’ identified by ‘rootroot’ 【給mysql用戶分配權限】

flush privileges;

vim /etc/sysconfig/iptables【編輯訪問端口號】

###############################################################

-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(添加3306的端口號)

###############################################################

service iptables restart

netstat -ntlp

mysql -u root -p (命令未找到使用: ln -s /usr/local/mysql/bin/mysql /usr/bin)

create user ‘tdc’@’%’ identified by ‘P@ssw0rd’;【創建數據庫訪問用戶】

create database if not exists `tdcdb`;【創建數據庫】

grant all privileges on tdcdb.* to ‘tdc’@’%’ identified by ‘P@ssw0rd’;【給tdc用戶分配訪問密碼】

flush privileges;

vi /etc/my.cnf【編輯配置文件,支持語言設置】

###############################

[client]

default-character-set=utf8

[mysqld]

character-set-server=utf8

[mysql]

default-character-set=utf8

###############################

service mysql stop【重新啟動mysql服務】

service mysql start

======================================================

linux 常用命令:

pwd:查看當前路徑

ll:2個小寫的L,查看當前目錄下的所有文件

cd:打開目錄,包括路徑地址及文件夾

vi 文件名:編輯linux下的文件,使用大寫的【I】命令來進行編輯,編輯完成後點擊【ESC】按鈕跳出編輯,輸入【:wq!】命令來退出保存;

注意:linux的文件不能打開直接修改,只能通過vi命令進行修改

======================================================

卸載程序的方式:

ps -ef | grep mysql

/etc/init.d/mysql status

whereis mysql

find / -name mysql【找到所有文件名為mysql的文件列表】

rm -rf /usr/local/mysql/【使用rm命令來移除列表中的文件】

rm -rf /etc/my.cnf【使用rm命令來移除列表中的文件】

如何在linux中安裝mysql

1.首先在liunx下安裝Mysql數據庫

~$ sudo apt-get install mysql-server #安裝Mysql服務器端

~$ ps -aux|grep mysql #檢查Mysql服務器進程

beili 10301 0.0 0.0 37080 3604 pts/7 S+ 5月20 0:00 mysql -u root -p

mysql 25125 0.0 0.0 4472 1704 ? Ss 09:51 0:00 /bin/sh /usr/bin/mysqld_safe

mysql 25496 0.0 3.1 859956 127084 ? Sl 09:51 0:01 /usr/sbin/mysqd –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib/mysql/plugin –log-error=/var/log/mysql/error.log –pid-file=/var/run/mysqld/mysqld.pid –socket=/var/run/mysqld/mysqld.sock –port=3306

beili 26652 0.0 0.0 13708 2180 pts/19 S+ 10:32 0:00 grep –color=auto mysql

~$ netstat -nlt|grep 3306 #檢查Mysql服務器佔用端口

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

~$ /etc/init.d/mysql status # 通過啟動命令檢查Mysql服務器狀態

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since 四 2015-05-21 09:51:13 CST; 43min ago

Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)

Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

~$ service mysql status # 通過系統服務檢查Mysql服務器狀態

● mysql.service – MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since 四 2015-05-21 09:51:13 CST; 44min ago

Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)

Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

~$ whereis mysql # 查看mysql各個文件安裝的目錄

mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

2.訪問和配置Mysql

$ mysql -u root -p

Enter password:

mysql默認的字符集為latin1的,所以要改為utf8的。很多網上的文章執行“sudo vi /etc/mysql/my.cnf”,可是打開一看,裡面就兩行話:

!includedir /etc/mysql/conf.d/

!includedir /etc/mysql/mysql.conf.d/

想來mysql的配置文件應該是在那兩個文件夾下面,於是嘗試之下打開了/etc/mysql/mysql.conf.d/ 下的mysqld.cnf文件,執行下面的命令:

~$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

[client]

default-character-set=utf8

[mysqld_safe]

socket = /var/run/mysqld/mysqld.sock

nice = 0

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci

註:棕色部分是添加的內容

重啟mysql服務,並查看字符集的設置情況:

~$ sudo /etc/init.d/mysql restart

~$ mysql -u root -p

mysql show variables like “%char%”

+————————–+—————————-+

| Variable_name | Value |

+————————–+—————————-+

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

如何在linux上安裝mysql

可以yum -y install mysql mysql-devel mysql-server

1

查找以前是否安裝有mysql,使用下面命令:

rpm -qa|grep -i mysql

如果顯示有如下包則說明已安裝mysql

mysql-4.1.12-3.RHEL4.1

mysqlclient10-3.23.58-4.RHEL4.1

2

沒有的話下載mysql的rpm包

可以通過wget下載

(1)MySQL-server-5.6.10-1.rhel5.x86_64.rpm:MySQL服務器;

(2)MySQL-client-5.6.10-1.rhel5.x86_64.rpm:MySQL客戶端;

(3)MySQL-devel-5.6.10-1.rhel5.x86_64.rpm:Mysql開發依賴包。

下載後放到Liunx服務器中

3

安裝MySQL Server的rpm包

rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm

安裝完成後會生成root用戶的隨機密碼,請使用“cat /root/.mysql_secret”或類似命令進行查看。

4

安裝MySQL客戶端

rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm

5

安裝MySQL開發依賴包

rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm

6

啟動msyql

安裝完成後mysql是沒有啟動的,運行mysql命令會提示如下錯誤:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

可使用如下命令啟動MySQL:

service mysql start

或者使用如下命令:

/etc/init.d/mysql start

可使用SET PASSWORD命令修改root用戶的密碼,參考如下:SET PASSWORD = PASSWORD(‘root123456’);

7

登錄MySQL

使用mysql命令登錄MySQL服務器,運行MySQL的命令時,會提示需要設置root用戶密碼

怎樣在Linux環境下安裝部署MySQL數據庫系統

在Linux安裝軟件需要預先做好如下一些準備:準備好Linux操作系統如:CentOS7。配置好yum源。

完成上述準備後,就可以動手安裝MySQL數據庫了。主要安裝步驟如下:

1. 禁用selinux

setenforce 0

2. 上傳安裝文件到Linux

3.解壓rpm包

tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar

4.安裝軟件

yum install mysql-community-{libs,client,common,server}-*.rpm

5.啟動mysql數據庫初始化

systemctl start mysqld

6.修改vi /etc/my.cnf

添加:

[mysqld]

#可以在表中錄入中文

character-set-server=utf8 #

explicit-defaults-for-timestamp

# 禁用當前密碼認證策略,可以使用簡單密碼(生產環境不適用)

validate_password=0

7.重啟mysql服務

systemctl restart mysqld

8.找臨時登錄密碼

grep -i “temporary password” /var/log/mysqld.log

9.連接MySQL數據庫

mysql -uroot -p 輸入臨時密碼

10.修改root用戶登錄密碼為簡單密碼(生產環境不適用)

alter user root@localhost identified by ”;

11.配置MYSQL_PS1環境變量

修改家目錄下:.bash_profile文件,添加

export MYSQL_PS1=”\u@\h[\d]”

12.使新環境變量生效

source /root/.bash_profile

13.重新連接mysql驗證

mysql -uroot -p

除了上述安裝方式以外,可能在公司中會遇到安裝指定版本的需求,那麼如何安裝指定版本的MySQL數據呢?這時我們可以採用下載指定版本安裝包進行安裝的方式,主要步驟如下,假設CentOS7 linux最小安裝,已經配置好yum。首先檢查是否安裝numactl包

rpm -qa|grep numactl

yum install numactl-libs-* # 如果沒有安裝需要安裝。檢查是否安裝libaio包

rpm -qa|grep libaio

yum install libaio-* # 如果沒有安裝需要安裝

具體安裝步驟如下:

* 禁用selinux

setenforce 0

* 上傳安裝文件到Linux

mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

* 創建mysql用戶組和用戶

groupadd -g 27 -r mysql

#-r創建系統賬戶,-M 不創建用戶家目錄 -N 不創建和用戶名一樣的用戶組

useradd -M -N -g mysql -r -s /bin/false -c “MySQL Server” -u 27 mysql

id mysql

* 上傳安裝包到root家目錄

* 解壓二進制文件到/usr/local

tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local

* 解壓目錄改名為mysql

cd /usr/local

ls -l

mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql

* 環境變量中添加mysql/bin目錄

vi /root/.bash_profile

修改PATH=/usr/local/mysql/bin:$PATH:$HOME/bin

添加 export MYSQL_PS1=”\u@\h[\d]”

source /root/.bash_profile

* 創建/usr/local/mysql/etc/my.cnf選項文件 (也可以使用默認的/etc/my.cnf選項文件)

mkdir -p /usr/local/mysql/etc

mkdir -p /usr/local/mysql/mysql-files

* 編輯選項文件my.cnf填寫默認選項

vi /usr/local/mysql/etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/usr/local/mysql/data/mysql.sock

log-error=/usr/local/mysql/data/mysqld.err

pid-file=/usr/local/mysql/data/mysqld.pid

secure_file_priv=/usr/local/mysql/mysql-files

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

Explicit-defaults-for-timestamp

character-set-server=utf8

[mysql]

socket=/usr/local/mysql/data/mysql.sock

* 初始化數據目錄

cd /usr/local/mysql

mkdir data

chmod 750 data

chown mysql:mysql data

* 初始化數據庫

cd /usr/local/mysql

bin/mysqld –defaults-file=/usr/local/mysql/etc/my.cnf –initialize

* 使用systemd管理mysql

例如:systemctl {start|stop|restart|status} mysqld

cd /usr/lib/systemd/system

touch mysqld.service

chmod 644 mysqld.service

vi mysqld.service

# 添加以下內容

[Unit]

Description=MySQL Server

Documentation=man:mysqld(7)

Documentation=

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

Type=forking

PIDFile=/usr/local/mysql/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.

TimeoutSec=0

# Start main service

ExecStart=/usr/local/mysql/bin/mysqld –defaults-file=/usr/local/mysql/etc/my.cnf –daemonize –pid-file=/usr/local/mysql/data/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation

EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit

LimitNOFILE = 65535

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

以上內容中注意:The –pid-file option specified in the my.cnf configuration file is ignored by systemd.

默認:LimitNOFILE = 5000,如果連接數(max_connection)需要調大,可以將LimitNOFILE 設置為最大65535

* 創建mysql.conf文件

cd /usr/lib/tmpfiles.d

#Add a configuration file for the systemd tmpfiles feature. The file is named mysql.conf and is placed in /usr/lib/tmpfiles.d.

cd /usr/lib/tmpfiles.d

touch mysql.conf

chmod 644 mysql.conf

* mysql.conf添加內容

vi mysql.conf

添加以下語句:

d /usr/local/mysql/data 0750 mysql mysql –

* 使新添加的mysqld服務開機啟動

systemctl enable mysqld.service

* 手動啟動mysqld

systemctl start mysqld

systemctl status mysqld

* 獲得mysql臨時登錄密碼

cat /usr/local/mysql/data/mysqld.err | grep “temporary password”

* 客戶端登錄連接mysql服務器

mysql -uroot -p

輸入臨時密碼

* 修改MySQL用戶root@localhost密碼

mysql alter user root@localhost identified by ”; #此處為了方便設置為空密碼

* 測試新密碼連接MySQL服務

mysql -uroot -p

至此,我們就完成了在Linux環境下安裝MySQL的任務。通過這兩種方式我們可以體會到在Linux環境下安裝軟件的基本思路及方法。

如何安裝mysql,Linux下mysql安裝

不同的linux版本安裝mysql的方法略有不同,這裡以debian和redhat兩個系列的linux版本為例簡要說明安裝方法。

一、、紅帽系列的linux版本

1、安裝服務端

yum install mysql-server mysql-devel

說明:yum是redhat系列linux版本上的包管理工具,install是yum

的參數表示安裝,mysql-server是mysql的服務端,mysql-devel是

編譯模塊時所需要的包和庫文件。

2、安裝客戶端

yum install mysql

說明:yum是redhat系列linux版本上的包管理工具,install是yum

的參數表示安裝,mysql

二、debian系列linux版本。

1、安裝服務端

sudo apt-get install mysql-server

說明:sudo用於提升權限 ,apt-get是debian系列linux版本的包管理工

具,install是其參數,用於安裝軟件包,mysql-server是mysql的服務

端軟件包。

2、安裝客戶端

sudo apt-get install mysql-client

說明:sudo用於提升權限 ,apt-get是debian系列linux版本的包管理工

具,install是其參數,用於安裝軟件包,mysql-clinet是mysql的客戶端

軟件包。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/309179.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2025-01-04 19:30
下一篇 2025-01-04 19:30

相關推薦

  • 如何修改mysql的端口號

    本文將介紹如何修改mysql的端口號,方便開發者根據實際需求配置對應端口號。 一、為什麼需要修改mysql端口號 默認情況下,mysql使用的端口號是3306。在某些情況下,我們需…

    編程 2025-04-29
  • Python操作MySQL

    本文將從以下幾個方面對Python操作MySQL進行詳細闡述: 一、連接MySQL數據庫 在使用Python操作MySQL之前,我們需要先連接MySQL數據庫。在Python中,我…

    編程 2025-04-29
  • MySQL遞歸函數的用法

    本文將從多個方面對MySQL遞歸函數的用法做詳細的闡述,包括函數的定義、使用方法、示例及注意事項。 一、遞歸函數的定義 遞歸函數是指在函數內部調用自身的函數。MySQL提供了CRE…

    編程 2025-04-29
  • Java 監控接口返回信息報錯信息怎麼處理

    本文將從多個方面對 Java 監控接口返回信息報錯信息的處理方法進行詳細的闡述,其中包括如何捕獲異常、如何使用日誌輸出錯誤信息、以及如何通過異常處理機制解決報錯問題等等。以下是詳細…

    編程 2025-04-29
  • 使用Python爬蟲獲取電影信息的實現方法

    本文將介紹如何使用Python編寫爬蟲程序,來獲取和處理電影數據。需要了解基本的Python編程語言知識,並使用BeautifulSoup庫和Requests庫進行爬取。 一、準備…

    編程 2025-04-28
  • MySQL bigint與long的區別

    本文將從數據類型定義、存儲空間、數據範圍、計算效率、應用場景五個方面詳細闡述MySQL bigint與long的區別。 一、數據類型定義 bigint在MySQL中是一種有符號的整…

    編程 2025-04-28
  • Python爬取網頁信息

    本文將從多個方面對Python爬取網頁信息做詳細的闡述。 一、爬蟲介紹 爬蟲是一種自動化程序,可以模擬人對網頁進行訪問獲取信息的行為。通過編寫代碼,我們可以指定要獲取的信息,將其從…

    編程 2025-04-28
  • MySQL左連接索引不生效問題解決

    在MySQL數據庫中,經常會使用左連接查詢操作,但是左連接查詢中索引不生效的情況也比較常見。本文將從多個方面探討MySQL左連接索引不生效問題,並給出相應的解決方法。 一、索引的作…

    編程 2025-04-28
  • 如何使用Python執行Shell命令並獲取執行過程信息

    本文將介紹如何使用Python執行Shell命令並獲取執行過程信息。我們將從以下幾個方面進行闡述: 一、執行Shell命令 Python內置的subprocess模塊可以方便地執行…

    編程 2025-04-28
  • Python實現身份信息模擬生成與查驗

    本文將從以下幾個方面對Python實現身份信息模擬生成與查驗進行詳細闡述: 一、身份信息生成 身份信息生成是指通過代碼生成符合身份信息規範的虛假數據。Python中,我們可以使用f…

    編程 2025-04-27

發表回復

登錄後才能評論