linux下安装mysql的方式_linux下安装mysql的两种方式
linux下安裝mysql的兩種方式
1 源碼安裝
1 創建mysql用戶:
useradd mysql
passwd mysql
2 解壓縮下載的mysql包:
tar -zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz -C /home/mysql
cd /home/mysql
mv mysql-5.6.41-linux-glibc2.12-x86_64/* .
rm -rf mysql-5.6.41-linux-glibc2.12-x86_64/
yum -y install perl perl-devel gcc kernel-devel autoconf
3 將mysql目錄的權限授給mysql用戶和mysql組:
chown -R mysql:mysql /home/mysql/
4 切換到mysql用戶,執行安裝:
su - mysql
/home/mysql/scripts/mysql_install_db --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
(注意,如果安裝報錯:scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory,切換到root用戶,安裝perl以及perl-devel,執行命令:
yum -y install perl perl-devel)
創建錯誤日志
touch mysql_error.log
5 切換到root用戶,復制并修改配置文件,添加msql服務:
復制文件:
cd /home/mysql/support-files
cp my-default.cnf /etc/my.cnf
vi /etc/my.cnf
[mysqld]
basedir = /home/mysql
datadir = /home/mysql/data
socket = /tmp/mysql.sock
log-error=/home/mysql/mysql_error.log
skip-name-resolve
character_set_server=utf8
#init_connect=‘set names utf8’
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names = 1
max_allowed_packet = 32M
table_open_cache = 1024
sort_buffer_size = 4M
join_buffer_size = 2M
net_buffer_length = 8M
read_buffer_size = 4M
read_rnd_buffer_size = 8M
thread_cache_size = 300
query_cache_size = 1024M
query_cache_limit = 2M
thread_concurrency = 8
wait_timeout = 315360000
max_connections = 300
max_connect_errors=1844674407370954751
max_connect_errors = 10000
#event_scheduler=1
#innodb_log_file_size=256M
innodb_buffer_pool_size = 4094M
innodb_additional_mem_pool_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_thread_concurrency=8
#innodb_sort_buffer_size=32M
innodb_open_files=4096
innodb_write_io_threads=2
innodb_read_io_threads=2
innodb_max_dirty_pages_pct = 90
innodb_file_per_table=1
[client]
socket=/tmp/mysql.sock
default-character-set=utf8
加入系統服務:
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
修改文件中的兩個變更值
basedir=/home/mysql/
datadir=/home/mysql/data/
6 配置mysql的環境變量:
vi /etc/profile
添加如下內容:
export PATH=$PATH:/home/mysql/bin
source /etc/profile
7 啟用mysql:
chkconfig --add mysql
chkconfig mysql on
service mysql start
Starting MySQL… SUCCESS!
8 設置mysql的root用戶密碼:
/home/mysql/bin/mysqladmin -u root password ‘123456’
9 給root用戶配置遠程訪問權限,設置后可通過客戶連接。
GRANT ALL PRIVILEGES on . to ‘root’@’%’ identified by ‘123456’;
flush privileges;
如果遇到報錯
1 Starting MySQL… ERROR! The server quit without updating PID file (/home/mysql/data/zh.pid).
cat /home/mysql/mysql_error.log
2018-12-27 16:01:48 5552 [ERROR] Can’t start server : Bind on unix socket: Address already in use
2018-12-27 16:01:48 5552 [ERROR] Do you already have another mysqld server running on socket: /tmp/mysql.sock ?
2018-12-27 16:01:48 5552 [ERROR] Aborting
刪除 /tmp/mysql.sock
rm -rf /tmp/mysql.sock
2、MySQL server PID file could not be found!
Starting MySQL… ERROR! The server quit without updating PID file (/home/mysql/data/ss2.pid).
一種可能是mysql目錄權限不對
一種可能是,如果手動可以起來,./mysqld --defaults-file=/etc/my.cnf --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
service mysql start 起不來,那就是/etc/init.d/mysql配置有問題,重新配置
2 rpm安裝
2.1解壓
tar -xvf MySQL-5.6.36-1.el6.x86_64.rpm-bundle.tar
2.2 安裝server client devel
rpm -ivh MySQL-server-5.6.36-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.36-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.6.36-1.el6.x86_64.rpm
2.3將MySQL的配置文件拷貝到/etc目錄下。
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
.2.4分別運行下述命令,初始化MySQL及設置密碼。
/usr/bin/mysql_install_db #初始化MySQL
service mysql start #啟動MySQL
cat /root/.mysql_secret #查看root賬號的初始密碼,會出現下述所示信息
The random password set for the root user at Tue Sep 12 22:19:19 2017 (local time): 8BOldGKvNrvsb8WB
2.5設置密碼
用上述密碼登錄:mysql -u root -p8BOldGKvNrvsb8WB登錄
set password=password(‘123456’);
2.6.設置開機啟動
chkconfig mysql on
[root@zs2 mysql]# chkconfig --list | grep mysql
mysql 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
上面打印出來的內容中,2~5為on就是開機啟動了。
2.7修改/etc/my.cnf
設置MySQL的字符集,配置MySQL表明不區分大小寫(默認情況下,MySQL對表名區分大小寫,列名不區分大小寫)。在[mysqld]下面加入如下內容:
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1 – 列名不區分大小寫
max_connections=1000
查看默認引擎 show engines
查看默認目錄 show variables like ‘datadir’
查看字符集:
show variables like ‘%char%’;
2.8MySQL的默認文件路徑
/var/lib/mysql/ #數據庫目錄
/usr/share/mysql #配置文件目錄
/usr/bin #相關命令目錄 #啟動腳本
2.9修改數據文件路徑
mysql -uroot -p 登錄
show variables like ‘%datadir%’
可查看當前目錄
cp /var/lib/mysql /home/mysql將默認的文件目錄拷貝過來
修改my.cnf,修改datadir=
2.9報錯
1、Host is not allowed to connect to this MySQL server解決方法
先說說這個錯誤,其實就是我們的MySQL不允許遠程登錄,所以遠程登錄失敗了,解決方法如下:
在裝有MySQL的機器上登錄MySQL mysql -u root -p密碼
執行use mysql;
執行update user set host = ‘%’ where user = ‘root’;這一句執行完可能會報錯,不用管它。
執行FLUSH PRIVILEGES;
2、MySQL無法重啟問題解決
service mysqld stop
Warning: World-writable config file ‘/etc/my.cnf’ is ignored
MySQL manager or server PID file could not be found![FAILED]
可以看到mysql停止不了
查看my.cnf的權限
ls -l /etc/my.cnf
-rwxrwxrwx 1 root root 4878 Jul 30 11:31 /etc/my.cnf
權限777,任何一個用戶都可以改my.cnf,存在很大的安全隱患.
chmod 644 /etc/my.cnf
my.cnf設置為用戶可讀寫,其他用戶不可寫.
總結
以上是生活随笔為你收集整理的linux下安装mysql的方式_linux下安装mysql的两种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java排序算法总结_排序算法总结及Ja
- 下一篇: mysql建立电影表_【代码片段】MyS