Linux 下安裝mysql 服務

2021-08-19 01:38:29 字數 3206 閱讀 3713

1、這裡我將mysql安裝在/usr/local/mysql目錄裡面,也可以安裝在其他地方;

mkdir /usr/local/mysql
3、解壓並複製

tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar

.gzmv mysql-5.7.11-linux-glibc2.5-x86_64/*

/usr/local/mysql/

4、建立data目錄

mkdir /usr/local/mysql/data
5、建立mysql使用者組及其使用者

groupadd mysql

useradd -r -g mysql mysql

如果已經存在,沒關係,不影響安裝

6、初始化資料

[root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

2016-01-20 02:47:35 [warning] mysql_install_db is deprecated. please consider switching to mysqld --initialize

2016-01-20 02:47:45 [warning] the bootstrap log isn't empty:

2016-01-20 02:47:45 [warning] 2016-01-19t18:47:36.732678z 0 [warning] --bootstrap is deprecated. please consider using --initialize instead

2016-01-19t18:47:36.750527z 0 [warning] changed limits: max_open_files: 1024 (requested 5000)

2016-01-19t18:47:36.750560z 0 [warning] changed limits: table_open_cache: 431 (requested 2000)

7、複製配置檔案到 /etc/my.cnf

cp -a ./support-files/my-default.cnf /etc/my.cnf (選擇y)
我安裝的沒有my-default.cnf,我從別的地方複製到這裡乙個

8、mysql的服務指令碼放到系統服務中

cp -a ./support-files/mysql.server /etc/init.d/mysqld

修改my.cnf檔案

# these are commonly set, remove the # and set as required.

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

# server_id = .....

socket = /tmp/mysql.sock //此處因為在我之前有人在測試環境安裝過mysql,所以不知道為什麼這個位址,我寫/var/lib/mysql.sock才好使

character-set-server = utf8

# remove leading # to set options mainly useful for reporting servers.

# the server defaults are faster for transactions and fast selects.

# adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128m

# sort_buffer_size = 2m

# read_rnd_buffer_size = 2m

9、建立in

ln -s /usr/local/mysql/  /usr/bin/
10、啟動服務

service mysqld start
11、初始化密碼

mysql5.7會生成乙個初始化密碼,在root中.mysql_secret檔案中。

[root@localhost ~]# cat /root/.mysql_secret

# password set

for user '

root@localhost

' at 2017-03-16

00:52:34

ws;fmt7yh0cm

12、登入並修改密碼 ,如果此處一直報密碼輸入錯誤,可以在my.cnf中 寫

原創:

可以免密碼登入之後:

用修改後的密碼登入之後,再次登入,再用alter修改密碼就可以正常使用了

13、退出重新登入,完成

mysql> show databases;

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

| database           |

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

| information_schema |

| mysql              |

| performance_schema |

| sys                |

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

rows in set (0.11 sec)

原創:

Linux下Mysql服務安裝 1

右鍵複製鏈結位址 未安裝wget指令,需要先安裝。yum y install wget 然後執行 wget yum y localinstall mysql80 community release el7 11.noarch.rpm yum y install mysql community ser...

linux伺服器下安裝mysql

命令 rpm qa grep mysql 無輸出則代表沒安裝命令 wget命令 sudo rpm ivh mysql community release el7 5.noarch.rpm命令 sudo yum install mysql server命令 service mysqld restart...

在linux下安裝mysql伺服器

1.cd opt soft 2.安裝 make wget tar zxvf make 3.82.tar.gz cd make 3.82 configure make make install cd 3.安裝 bison wget tar zxvf bison 2.5.tar.gz cd bison ...