一、實驗環境
環境:CentOS6.5
軟體:mysql-5.5.32-linux2.6-x86_64
二、實驗步驟
二進制包安裝mysql資料庫,二進制安裝無需編譯,即直接解壓放置安裝的目錄即可
1)二進制安裝mysql5.5.32-linux2.6-x86_64.tar.gz ,解壓。
tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz
mv mysql-5.5.32-linux2.6-x86_64 /application/mysql
2)建立mysql使用者
useradd mysql -s /sbin/nologin/ -M
3)授權/application/mysql
chown -R mysql.mysql /application/mysql
4)初始化資料庫
cd /application/mysql
mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/
WARNING: The host 'lnmp01' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
160609 22:14:24 [Note] /application/mysql/bin/mysqld (mysqld 5.5.49) starting as process 10430 ...
ERROR: 1005 Can't create table 'tmp_db' (errno: 13)
160609 22:14:24 [ERROR] Aborting
160609 22:14:24 [Note] /application/mysql/bin/mysqld: Shutdown complete
Installation of system tables failed! Examine the logs in
/application/mysql/data/ for more information.
You can try to start the mysqld daemon with:
shell> /application/mysql/bin/mysqld --skip-grant &
and use the command line tool /application/mysql/bin/mysql
to connect to the mysql database and look at the grant tables:
shell> /application/mysql/bin/mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /application/mysql/data/ that may be helpful.
Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.
Please check all of the above before submitting a bug report
at http://bugs.mysql.com/
如出現上訴錯誤,原因是mysql無法向/tmp/目錄寫入'tmp_db',解決方法:給/tmp目錄授權:chown -R mysql.mysql /tmp/,再次初始化即可。
160610 0:36:37 [Note] /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 11463 ...
OK
Filling help tables...
160610 0:36:37 [Note] /application/mysql//bin/mysqld (mysqld 5.5.49) starting as process 11470 ...
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
出現兩個OK代表mysql資料庫安裝成功。
5)生成配置檔案
\cp /application/mysql/support-files/mysql-small.cnf /etc/my.cnf
6)配置啟動mysql
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
/application/mysql/bin/mysqld_safe & 背景啟動mysql
7)寫入環境變量
vi /etc/profile
PATH="/application/mysql/bin:$PATH"
source /etc/profile
或者
root@lnmp01 application]# cp /application/mysql/bin/* /usr/local/sbin/
[root@lnmp01 application]# which mysql
/usr/local/sbin/mysql
8)修改啟動方法
cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
9.登入mysql
[root@lnmp01 application]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
10.設定密碼和更改密碼
/application/mysql/bin/mysqladmin -u root -password 'new-password'
/application/mysql//bin/mysqladmin -u root -h lnmp01 password 'new-password'
mysqladmin -uroot password "chen" ---設定密碼
mysqladmin -uroot -pchen password "chen123"---修改密碼
本文轉自chengong1013 51CTO部落格,原文連結:http://blog.51cto.com/purify/1790522,如需轉載請自行聯系原作者