手動安裝MySQL資料庫

2021-08-03 02:12:18 字數 4178 閱讀 1521

新手學習mysql,在阿里雲主機上安裝mysql5.7.18.

參考文件: 安裝步驟

錯誤檢查: can』t connect to local mysql server through socket 『/tmp/mysql.sock』 (2)

獲取安裝包,解壓至安裝目錄,新增使用者和組,更改所有者和所屬組

wget   

tar zxf mysql-

5.7.18

-linux

-glibc2

.5-x86_64

.tar.gz -c /usr/local

cd /usr/local

mv mysql-

5.7.18

-linux

-glibc2

.5-x86_64

/ mysql

groupadd mysql

useradd -r

-g mysql mysql

chown -r mysql:mysql mysql/

5.7.18版本中./support-files目錄下缺少乙個my-default.cnf檔案,該檔案可以從網上找到例子,這是我找到的

# for advice on how to change settings please see  

#

# *** do not edit this file. it's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of mysql.

[mysqld]

sql_mode=no_engine_substitution,strict_trans_tables

# 一般配置選項

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

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

#網上很多教程裡socket的路徑是/tmp/mysql.sock

#我一直不行,按照本文配置成功,後續還有地方要修改

character-set-server=utf8

#下面是可選項,要不要都行,如果出現啟動錯誤,則全部注釋掉,保留最基本的配置選項,然後嘗試新增某些配置項後啟動,檢測配置項是否有誤(首次安裝報錯,以下內容已刪)

back_log = 300

max_connections = 3000

max_connect_errors = 50

table_open_cache = 4096

max_allowed_packet = 32m

#binlog_cache_size = 4m

max_heap_table_size = 128m

read_rnd_buffer_size = 16m

sort_buffer_size = 16m

join_buffer_size = 16m

thread_cache_size = 16

query_cache_size = 128m

query_cache_limit = 4m

ft_min_word_len = 8

thread_stack = 512k

transaction_isolation = repeatable-read

tmp_table_size = 128m

#log-bin=mysql-bin

long_query_time = 6

server_id=1

innodb_buffer_pool_size = 1g

innodb_thread_concurrency = 16

innodb_log_buffer_size = 16m

innodb_log_file_size = 512m

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

innodb_file_per_table = on

[mysqldump]

quick

max_allowed_packet = 32m

[mysql]

no-auto-rehash

default-character-set=utf8

safe-updates

[myisamchk]

key_buffer = 16m

sort_buffer_size = 16m

read_buffer = 8m

write_buffer = 8m

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 8192

註冊和初始化mysql服務

一些老版本的mysql是通過mysql_install_db的方式安裝,在5.7的版本中不推薦,改用mysqld安裝

bin/mysqld--

initialize

-insecure--

user=mysql--

basedir=/usr/local/mysql/--

datadir=/usr/local/mysql/data/

將support-files目錄下的檔案拷貝到/etc/

cp ./support-files/my-default.cnf  /etc/my.cnf

cp ./support-files/mysql.service /etc/init.d/mysqld

啟動mysql服務

./bin/mysqld_safe --user=mysql &
加了&表示後台執行,執行jobs看到mysqld_safe在執行即可

出現以下報錯

can』t connect to local mysql server through socket 『/tmp/mysql.sock』 (2)

報錯恢復是因為在my.conf配置檔案中socket = /var/run/mysqld/mysqld.sock,而不是/tmp目錄下,所以要建立乙個軟連線

ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
正常情況應配置到/tmp/目錄下,但本人一直配置不成功,改到/var/run,新增軟連線成功

登陸mysql

手工設定密碼

mysqladmin -uroot password '123456'
登陸

enter password:

welcome to

the mysql monitor. commands end

with ; or \g.

your mysql connection idis3

server version: 5.7

.18 mysql community server (gpl)

oracle is a registered trademark of oracle corporation and/or

itsaffiliates. other names may be trademarks of their respective

owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql>

手動備份MySQL資料庫 手動備份mysql資料庫

paths 檔案路徑 user 資料庫使用者名稱 pass 資料庫密碼 database 資料庫名 public static boolean backup string paths,string user,string pass,string database outstr sb.tostring...

mysql 資料庫安裝命令 MySQL 資料庫安裝

4.安裝資料庫 scripts mysql install db user mysql datadir usr local mysql data 這時候報錯了,提示我們沒有找到.scripts mysql install db 這個裡這個檔案或者目錄 因為 mysql install db 這個檔案...

mysql 資料庫安裝

mysql v4.1.10 for linux 乙個多執行緒的 結構化查詢語言 sql 資料庫伺服器,它執行效能高,執行速度快,易於使用。目前國內不少商業web虛擬主機產品都提供對它的支援。1 解壓縮mysql安裝檔案至某一目錄。如 usr local src 2 增加使用者組和使用者 groupa...