通過RPM包安裝Mysql
由於公司最近的也去需要,需要安裝Mysql作為數據服務器,服務器版本是redhat6。在redhat6的光盤中找到Mysql的RPM包就直接用RPM包來安裝Mysql,期間遇到看種種問題。
www.2cto.com
網上的介紹基本上都是一樣的。先安裝server,然後再安裝client。但是我的server始終安裝不上,總是提示
然後按照提示安裝perl-DBD-Mysql的相關包,還是報錯。後來發現這個包和mysql的server包存在互相依賴,所以將安裝服務器端的命令改為:
www.2cto.com
1.rpm -ivh mysql-server-5.1.47-4.el6.x86_64.rpm --nodeps
安裝成功
2.啟動mysql
/etc/init.d/mysqld start
無法啟動,這時按照提示運行命令 www.2cto.com
chown -R mysql:mysql /var/lib/mysql
再次啟動啟動成功
3.設置mysql root用戶的密碼:mysqladmin -uroot password '密碼'
4.登錄測試:mysql -u root -p
5.備份數據庫:mysqldump --add-drop-table --opt test > backup-file.sql
以下內容自己就比較懶了是轉載的
Mysql相關設置
1,密碼和登陸設置
我們可以用命令 mysql_secure_installation進行相關的設置
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
這裡我已經通過命令mysqladmin 更改過默認密碼 語法為:
mysqladmin -uroot password 'newpassword'
這裡我們鍵入新密碼
[root@test-1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
以上我們可以根據提示來一步一步操作,再次不做說明
3.2,MySQL默認的數據文件存儲目錄為/var/lib/mysql。假如要把目錄移到/home/data下需要進行下面幾步:
1.、home目錄下建立data目錄
cd /home
mkdir data
2、把MySQL服務進程停掉:
mysqladmin -u root -p shutdown
3、把/var/lib/mysql整個目錄移到 /home/data
mv /var/lib/mysql /home/data/
這樣就把MySQL的數據文件移動到了/home/data/mysql下
4、找到 my.cnf配置文件
如果/etc/目錄下沒有my.cnf配置文件,請到/usr/share/mysql/ 下找到*.cnf文件,拷貝其中一個到/etc/並改名為my.cnf)中。命令如下:
[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
說明在/usr/share/mysql/下面有四個不同模式mysql運行配置文件:
my-large.cnf
my-medium.cnf
my-small.cnf
my-huge.cnf
5、編輯MySQL的配置文件/etc/my.cnf
為保證MySQL能夠正常工作,需要指明mysql.sock文件的產生位置。 修改socket=/var/lib/mysql/mysql.sock 一行中等號右邊的值
為:/home/mysql/mysql.sock 。操作如下:
vi my.cnf ##用vi工具編輯my.cnf文件,找到下列數據修改之
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock ##原內容,為了更穩妥用“#”注釋此行
socket = /home/data/mysql/mysql.sock #加上此行
3.3為了在其它電腦上能用root用戶登錄,需進行以下動作:
1、mark@marklinux mark>mysql -h localhost -u root
//這樣應該可以進入MySQL服務器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
//賦予任何主機訪問數據的權限
例子:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.0.10' identified by 'skymobi' WITH GRANT
3.4相關說明:
3.4.1 Mysql默認安裝路徑
find / -name mysql
/usr/bin