標籤:
Mysql安裝配置
安裝依賴包及mysql:
yum –y install perl libaio numactl
rpm -ivh MySQL-shared-5.6.30-1.el6.x86_64.rpm
rpm -ivh MySQL-shared-compat-5.6.30-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.6.30-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm (需要/usr/bin/perl)
rpm -ivh MySQL-server-5.6.30-1.el6.x86_64.rpm (需要/usr/bin/perl、libaio.so.1、libnuma.so.1)
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2016-05-16 18:31:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-05-16 18:31:25 0 [Note] /usr/sbin/mysqld (mysqld 5.6.30) starting as process 5934 ...
2016-05-16 18:31:25 5934 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-05-16 18:31:25 5934 [Note] InnoDB: The InnoDB memory heap is disabled
2016-05-16 18:31:25 5934 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-05-16 18:31:25 5934 [Note] InnoDB: Memory barrier is not used
2016-05-16 18:31:25 5934 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-05-16 18:31:25 5934 [Note] InnoDB: Using Linux native AIO
2016-05-16 18:31:25 5934 [Note] InnoDB: Using CPU crc32 instructions
2016-05-16 18:31:25 5934 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-05-16 18:31:25 5934 [Note] InnoDB: Completed initialization of buffer pool
2016-05-16 18:31:25 5934 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-05-16 18:31:25 5934 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-05-16 18:31:25 5934 [Note] InnoDB: Database physically writes the file full: wait...
2016-05-16 18:31:26 5934 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-05-16 18:31:26 5934 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-05-16 18:31:26 5934 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-05-16 18:31:26 5934 [Warning] InnoDB: New log files created, LSN=45781
2016-05-16 18:31:26 5934 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-05-16 18:31:26 5934 [Note] InnoDB: Doublewrite buffer created
2016-05-16 18:31:26 5934 [Note] InnoDB: 128 rollback segment(s) are active.
2016-05-16 18:31:26 5934 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-05-16 18:31:26 5934 [Note] InnoDB: Foreign key constraint system tables created
2016-05-16 18:31:26 5934 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-05-16 18:31:26 5934 [Note] InnoDB: Tablespace and datafile system tables created.
2016-05-16 18:31:26 5934 [Note] InnoDB: Waiting for purge to start
2016-05-16 18:31:26 5934 [Note] InnoDB: 5.6.30 started; log sequence number 0
A random root password has been set. You will find it in ‘/root/.mysql_secret‘.
2016-05-16 18:31:27 5934 [Note] Binlog end
2016-05-16 18:31:27 5934 [Note] InnoDB: FTS optimize thread exiting.
2016-05-16 18:31:27 5934 [Note] InnoDB: Starting shutdown...
2016-05-16 18:31:28 5934 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2016-05-16 18:31:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-05-16 18:31:28 0 [Note] /usr/sbin/mysqld (mysqld 5.6.30) starting as process 5956 ...
2016-05-16 18:31:28 5956 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-05-16 18:31:28 5956 [Note] InnoDB: The InnoDB memory heap is disabled
2016-05-16 18:31:28 5956 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-05-16 18:31:28 5956 [Note] InnoDB: Memory barrier is not used
2016-05-16 18:31:28 5956 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-05-16 18:31:28 5956 [Note] InnoDB: Using Linux native AIO
2016-05-16 18:31:28 5956 [Note] InnoDB: Using CPU crc32 instructions
2016-05-16 18:31:28 5956 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-05-16 18:31:28 5956 [Note] InnoDB: Completed initialization of buffer pool
2016-05-16 18:31:28 5956 [Note] InnoDB: Highest supported file format is Barracuda.
2016-05-16 18:31:28 5956 [Note] InnoDB: 128 rollback segment(s) are active.
2016-05-16 18:31:28 5956 [Note] InnoDB: Waiting for purge to start
2016-05-16 18:31:28 5956 [Note] InnoDB: 5.6.30 started; log sequence number 1625977
2016-05-16 18:31:28 5956 [Note] Binlog end
2016-05-16 18:31:28 5956 [Note] InnoDB: FTS optimize thread exiting.
2016-05-16 18:31:28 5956 [Note] InnoDB: Starting shutdown...
2016-05-16 18:31:30 5956 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
啟動mysql:
service mysql start
查看預設密碼:
cat /root/.mysql_secret
# The random password set for the root user at Mon May 16 18:31:26 2016 (local time): Uc33BRidiw2E_9us
lR_i88Lp6EgM18FP
設定root密碼:
mysql - u root
mysql>set password=password(‘rootfllg’);
mysql>flush privileges;
mysql>exit;
/usr/bin/mysqladmin -u root password ‘new-password‘
/usr/bin/mysqladmin -u root -h wiki password ‘new-password‘
測試mysql守護進程:
cd /usr/share/mysql-test
perl mysql-test-run.pl
安全強化:
/usr/bin/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): Uc33BRidiw2E_9us
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] Y
New password:su********
Re-enter new password: su********
Password updated successfully!
Reloading privilege tables..
... Success!
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 (此處有bug,把root登入許可權全刪除了,因為預設root使用者就只能通過localhost訪問)
... 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] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
All done! If you‘ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
移動mysql資料目錄:
service mysql stop
cd /var/lib/mysql
mv mysql/ /data/mysql/
修改設定檔:
vi /usr/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
datadir = /data/mysql/
# port = .....
# server_id = .....
socket = /data/mysql/mysql.sock
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
啟動mysql服務:
service mysql start
跳過許可權控制,以管理員身份登入mysql:
service mysql stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql
mysql>
查看使用者權限:
mysql -uroot -p
mysql>select host,user from user where user="root";
mysql>select host,user,password from user;
忘記root密碼,恢複步驟:
service mysql stop
mysqld_safe --skip-grant-tables &
mysql -uroot
mysql>update mysql.user set password=password(‘mypassword’) whereuser=’root’;
mysql>flush privileges;
mysql>quit
service mysql start
mysql –uroot –p
當有其他有許可權使用者可以登入mysql時,允許root使用者遠端存取:
mysql –u username
mysql>update mysql.user setpassword=password(“new_password”) where user=’root’and host=’localhost’;
mysql> grant all on *.* to [email protected]‘localhost‘ identified by ‘yourpassword‘;
mysql> grant all on *.* to [email protected]‘%‘ identified by ‘yourpassword‘;
mysql>flush privileges;
mysql>exit;
如果新裝好的mysql執行安全強化指令碼mysql_secure_installation,將導致user表被情況,root使用者從本機也無法登入mysql。只能重裝mysql,重裝步驟如下:
1、卸載mysql包
rpm –qa | grep MySQL
MySQL-shared-compat-5.6.30-1.el6.x86_64
MySQL-client-5.6.30-1.el6.x86_64
MySQL-server-5.6.30-1.el6.x86_64
MySQL-shared-5.6.30-1.el6.x86_64
MySQL-devel-5.6.30-1.el6.x86_64
rpm –e MySQL-server-5.6.30-1.el6.x86_64
2、刪除相關檔案
rm -rf /var/lib/mysql/mysql (刪除資料檔案)
rm -f /root/.mysql_secure (刪除預設root密碼檔案,以便rpm包安裝時重建預設密碼,即便已經改過root密碼)
3、重新安裝mysql
rpm –ivh MySQL-server-5.6.30-1.el6.x86_64.rpm
4、修改root密碼
service mysqlstart
cat/root/.mysql_secure
mysql -uroot –p
mysql>setpassword=password(‘password’);
Mysql安裝配置