日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql操作常见问题_MySQL:常见使用问题

發(fā)布時間:2024/10/12 数据库 80 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql操作常见问题_MySQL:常见使用问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、Linux 上安裝MySQL

安裝步驟:

1)解壓 tar.gz文件shell>?tar?-zxvf?mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

2)初始化默認(rèn)數(shù)據(jù)庫(mysql、performace_schema、sys、information_schema)

在/home/bes/jinuo/mysql 目錄下的結(jié)構(gòu)如下:

/home/bes/jinuo/mysql

/mysql-5.7.9-glibc2.5-x86_64

/bin

/docs

/include

/lib

/man

/share

/support-files

/test

/ins1

/my-default.cnf

拷貝 support-files 目錄到你想要做mysql實例的目錄下,并編輯如下:

[mysqld]

basedir=/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64

datadir=/home/bes/jinuo/mysql/test/ins1/datadir

port=36001

server_id=36001

socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock

log-error=/home/bes/jinuo/mysql/test/mysqld.log

explicit_defaults_for_timestamp=true

character-set-server=utf8

collation-server=utf8_general_ci

skip-host-cache

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

然后執(zhí)行如下命令初始化:

普通用戶可以直接執(zhí)行如下命令:shell>?bin/mysql_install_db????#?Before?MySQL?5.7.6shell>?bin/mysqld?--initialize???#?MySQL?5.7.6?and?up

如果是操作每戶的root用戶創(chuàng)建mysql實例,創(chuàng)建實例時,需要指定為哪個用戶創(chuàng)建的實例。

也就是說,如果你是一個普通用戶 hello, 你可以使用上面 的命令直接 創(chuàng)建自己的實例。

如果要讓root用戶給你創(chuàng)建實例,需要在上面命令后面加上?--user=hello?參數(shù)。

root用戶:

shell>mysqld?--defaults-file=/your/mysql/cnf/path?--initialize-insecure?--user=username>mysqld?--defaults-=/your/mysql/cnf/path?--initialize-insecure

在初始化時,會為mysql root用戶 創(chuàng)建一個臨時密碼。臨時密碼的位置可以這樣找到:

MySQL?5.6.x?:

A?RANDOM?PASSWORD?HAS?BEEN?SET?FOR?THE?MySQL?root?USER?!

You?will?find?that?password?in?'/root/.mysql_secret'.

You?must?change?that?password?on?your?first?connect,

no?other?statement?but?'SET?PASSWORD'?will?be?accepted.

See?the?manual?for?the?semantics?of?the?'password?expired'?flag.

Also,?the?account?for?the?anonymous?user?has?been?removed.

MySQL?5.7.x?:

如果初始化時使用的是??--initialize:

#?tail?-n1?/home/bes/jinuo/mysql/test/ins1/mysqld.log

2016-12-11T07:47:58.199154Z?1?[Note]?A?temporary?password?is?generated?for?root@localhost:?wzgds/:Kf2,g

如果初始化時使用的是??--initialize-insecure:

# tail -n1 /var/log/mysql/error.log? 2016-12-11T07:51:28.506142Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the?--initialize-insecure?option

所以,如果是5.7之上的版本,建議使用 ?--initialize-insecure方式來創(chuàng)建實例。這樣就可以直接使用mysqladmin來修改root密碼了。參見4)。

3)啟動數(shù)據(jù)庫

啟動MySQL Server:shelll>?/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysqld?--defaults-file=/home/bes/jinuo/mysql/test/ins1/my-default.cnf?&

4)知道密碼情況下,修改密碼

mysqladmin 提供了一套mysql的管理命令,其中有一個是password命令,用于修改密碼的。使用mysqladmin 來修改密碼的前提是你知道密碼,因為它內(nèi)部是先使用現(xiàn)有登錄到mysql server,然后修改密碼。

可以直接使用mysqladmin命令來修改密碼。例如修改root密碼,由安裝后的 空密碼修改為 12345678mysqladmin?-u?root?--socket=/home/bes/mysql/mysql.sock?password?12345678

如果在使用過程中,想要更換密碼由12345678變成123456:mysqladmin?-u?root?-p?12345678?--socket=/home/bes/mysql/mysql.sock?password?123456

修改其它用戶的密碼,是同樣 的方式。

5)為root授權(quán)限

mysql>?grant?all?on?*.*?to?'root'@'%'?identified?by?'yourRootPassword';

2、單機多實例安裝

如果在一臺機器上,要安裝多個mysql實例,只需要將重復(fù)執(zhí)行 1中的2)3)4)5)就可以了。

3、 不知root密碼情況下,修改root密碼、授權(quán)

該方式適用于,有root密碼,但是不知道root 密碼情況下。

a: 停止 MySQL Server

b: 繞過授權(quán)檢查方式啟動MySQL Server

shell>?/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysqld?--defaults-file=/home/bes/jinuo/mysql/test/ins1/my-default.cnf?--skip-grant-tables?&

c: root用戶登錄到mysql server上,并切換到mysql 庫

shell>?/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysql?--socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock?-uroot?-p

mysql>?use?mysql;

d: 修改root 用戶的密碼:

mysql>?update?mysql.user?set?authentication_string?=?password('mypassword')?where?user?=?'root';

mysql>?flush?privileges;

mysql>?quit;

e: 停止mysql server,正常啟動。

正常啟動的方式在前面 3)中已說過。

f: root 登錄后,進行授權(quán)調(diào)整:

shell>?/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysql?--socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock?-uroot?-p

Enter?Password

mysql>?grant?all?on?*.*?to?'root'@'%'?identified?by?'yourRootPassword';

總結(jié)

以上是生活随笔為你收集整理的mysql操作常见问题_MySQL:常见使用问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。